Module: Metanorma::Standoc::Regex

Included in:
Cleanup, Refs, Section
Defined in:
lib/metanorma/standoc/regex.rb

Constant Summary collapse

NUMERIC_REGEX =
%r{\A((\+|-)?\d*\.?\d+)([eE](\+|-){1}\d+)?\Z}
CONN_REGEX_STR =

extending localities to cover ISO referencing

"(?<conn>and|or|from|to)!".freeze
LOCALITIES =
"section|clause|part|paragraph|chapter|page|line|" \
"table|annex|figure|example|note|formula|list|time|anchor|" \
"locality:[^ \\t\\n\\r:,;=]+".freeze
LOCALITY_REGEX_STR =
"^((\#{CONN_REGEX_STR})?\n    (?<locality>\#{LOCALITIES})(\\\\s+|=)\n       (?<ref>[^\"][^ \\\\t\\\\n,:;-]*|\"[^\"]+\")\n         (-(?<to>[^\"][^ \\\\t\\\\n,:;-]*|\"[^\"]\"))?|\n  (?<locality2>whole|title|locality:[^ \\\\t\\\\n\\\\r:,;=]+))(?<punct>[,:;]?)\\\\s*\n (?<text>.*)$\n".freeze
LOCALITY_REGEX_VALUE_ONLY_STR =
"^(?<conn0>(\#{CONN_REGEX_STR}))\n  (?!whole|title|locality:)\n  (?<value>[^=,;:\\\\t\\\\n\\\\r]+)\n  (?<punct>[,;\\\\t\\\\n\\\\r]|$)\n".freeze
LOCALITY_REGEX_STR_TRIPLEDASH =
"^(?<locality>(\#{CONN_REGEX_STR})?\n    (\#{LOCALITIES})(\\\\s+|=))\n       (?<ref>[^\"][^ \\\\t\\\\n,:;-]*\n         -[^ \\\\t\\\\n,:;\"-]+\n         -[^ \\\\t\\\\n,:;\"]+)\n  (?<text>[,:;]?\\\\s*\n .*)$\n".freeze
TERM_REFERENCE_RE_STR =
"^(?<xref><(xref|concept)[^>]+>(.*?</(xref|concept)>)?)\n       (,\\s(?<text>.*))?\n$\n".freeze
TERM_REFERENCE_RE =
Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
Regexp::IGNORECASE | Regexp::MULTILINE)
ISO_REF =
%r{^<ref\sid="(?<anchor>[^"]+)">
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
(?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
ISO_REF_NO_YEAR =
%r{^<ref\sid="(?<anchor>[^"]+)">
      \[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+):
      (?:--|–|—|&\#821[12];)\]</ref>,?\s*
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
ISO_REF_ALL_PARTS =
%r{^<ref\sid="(?<anchor>[^"]+)">
      \[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9]+)
      (?::(?<year>--|–|—|&\#821[12];|[0-9][0-9-]+))?\s
      \(all\sparts\)\]</ref>,?\s*
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
NON_ISO_REF =
%r{^<ref\sid="(?<anchor>[^"]+)">
\[(?<usrlbl>\([^)]+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
NON_ISO_REF1 =
%r{^<ref\sid="(?<anchor>[^"]+)">
(?<usrlbl>\([^)]+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm

Instance Method Summary collapse

Instance Method Details

#to_regex(str) ⇒ Object



23
24
25
# File 'lib/metanorma/standoc/regex.rb', line 23

def to_regex(str)
  Regexp.new(str.gsub(/\s/, ""), Regexp::IGNORECASE | Regexp::MULTILINE)
end