:h1 id=regex res=300.Регулярные выражения

:p.В ряде директив
:link reftype=hd refid=cfgFiles.конфигурационных файлов:elink.
применяются регулярные выражения основанные на стандарте :hp9.POSIX:ehp9..

:p.Regular Expressions (:hp9.REs:ehp9.) are used to determine if a character
string of interest is matched somewhere in a set of character strings.
You can specify more than one character string for which you wish to
determine if a match exists. Regular Expressions use collating values
from the current locale definition file in the matching process.

:p.The search for a matching sequence starts at the beginning of the string
and stops when the first sequence matching the expression is found.
The first sequence is the one that begins earliest in the string.
If the pattern permits matching several sequences at this starting point,
the longest sequence is matched.

:p.See following section for details:
:p.:link reftype=hd refid=regexBase.Basic matching rules:elink.
.br
:link reftype=hd refid=regexAdd.Additional syntax specifiers:elink.
.br
:link reftype=hd refid=regexOrder.Order of precedence:elink.

:h2 id=regexBase res=310.Basic matching rules

:p.An ordinary character matches itself. The simplest form of regular expression is a string of
characters with no special meaning. 

:p.A special character preceded by a backslash matches itself.
For regular expressions (:hp9.REs:ehp9.), the special characters are: 

:p.:hp9.( ) + ? { | . [ \ * ^ $:ehp9.

:p.A period (:hp9..:ehp9.) without a backslash matches any single character
except the null character.

An expression within square brackets (:hp9.[ ]:ehp9.), called a bracket
expression, matches one or more characters or collating elements.
A bracket expression itself contains one or more expressions that
represent characters, collating symbols, equivalence or character classes,
or range expressions:

:dl compact tsize=28.
:dt.[string] 
:dd.Matches any of the characters specified. For example, :hp9.[abc]:ehp9.
matches any of :hp9.a:ehp9., :hp9.b:ehp9., or :hp9.c:ehp9..

:p.
:dt.[^string] 
:dd.Does not match any of the characters in string. The caret immediately
following the left bracket (:hp9.[:ehp9.) negates the characters that follow.
For example, :hp9.[^abc]:ehp9. matches any character or collating
element except :hp9.a:ehp9., :hp9.b:ehp9., or :hp9.c:ehp9..

:p.
:dt.[collat_sym-collat_sym] 
:dd.Matches any collating elements that fall between the two specified
collating symbols, inclusive. The two symbols must be different, and the
second symbol must collate equal to or higher than the first. For example,
in the English locale, :hp9.[r-t]:ehp9. would match any of :hp9.r:ehp9.,
:hp9.s:ehp9., or :hp9.t:ehp9..

:note text='Note:'. To treat the hyphen (:hp9.-:ehp9.) as itself, place it
either first or last in the bracket expression, for example:
:hp9.[-rt]:ehp9. or :hp9.[rt-]:ehp9..
Both of these expressions would match :hp9.-:ehp9., :hp9.r:ehp9., or :hp9.t:ehp9..

:p.
:dt.[[.collat_symbl.]]
:dd.Matches the collating element represented by the specified single or
multicharacter collating symbol :hp9.collat_symbl:ehp9.. For example,
assuming that :hp9.<ch>:ehp9. is the collating symbol for :hp9.ch:ehp9. in
the current locale, :hp9.[[.ch.]]:ehp9. matches the
character sequence :hp9.ch:ehp9.. (In contrast, :hp9.[ch]:ehp9. matches
:hp9.c:ehp9. or :hp9.h:ehp9..) If :hp9.collat_symbl:ehp9. is
not a collating element in the current locale, or if it has no characters
associated with it, it is treated as an invalid expression.

:p.
:dt.[[=collat_symbl=]]
:dd.Matches all collating elements that have a weight equivalent to the
specified single or multicharacter collating symbol :hp9.collat_symbl:ehp9..
For example, assuming :hp9.a:ehp9., :hp9.Е:ehp9., and :hp9.Г:ehp9. belong to
the same equivalence class, :hp9.[[=a=]]:ehp9. matches any
of the three.  If the collating symbol does not have any equivalents, it is
treated as a collating symbol and matches its corresponding collating element
(as for :hp9.[..]:ehp9.).

:p.
:dt.[[&colon.char_class&colon.]]
:dd.Matches any characters that belong to the specified character class
:hp9.char_class:ehp9.. For example, :hp9.[[&colon.alnum&colon.]]:ehp9.
matches all alphanumeric characters (characters for which isalnum would
return nonzero).

:note text='Note:'. To use the right bracket (:hp9.]:ehp9.) in a bracket
expression, you must specify it immediately following the left bracket
(:hp9.[:ehp9.) or caret symbol (:hp9.^:ehp9.).
For example, :hp9.[]x]:ehp9. matches the characters :hp9.]:ehp9.
and :hp9.x:ehp9.; :hp9.[^]x]:ehp9. does not match :hp9.]:ehp9. or :hp9.x:ehp9.;
:hp9.[x]]:ehp9. is not valid.
:edl.

:p.You can combine characters, special characters, and bracket expressions to
form :hp9.REs:ehp9. that match multiple characters and subexpressions. When you
concatenate the characters and expressions, the resulting :hp9.RE:ehp9. matches
any string that matches each component within the :hp9.RE:ehp9..
For example, :hp9.cd:ehp9. matches characters
3 and 4 of the string :hp9.abcde:ehp9.; :hp9.ab[[&colon.digit&colon.]]:ehp9.
matches :hp9.ab3:ehp9. but not :hp9.abc:ehp9..

:p.You can optionally enclose the concatenation in parentheses. 

:h2 id=regexAdd res=320.Additional syntax specifiers
 
:p.You can also use other syntax within an :hp9.REs:ehp9. to control
what it matches: 

:dl compact tsize=26.
:dt.(expression) 
:dd.Matches whatever expression matches. You only need to enclose an expression
in these delimiters to use operators (such as :hp9.*:ehp9. or :hp9.+:ehp9.)
on it.

:p.
:dt.expression*
:dd.Matches zero or more consecutive occurrences of what expression matches.
expression can be a single character or collating symbol or subexpression.
For example, :hp9.[ab]*:ehp9. matches :hp9.ab:ehp9. and :hp9.ababab:ehp9.;
:hp9.b*cd:ehp9. matches characters 3 to 7 of :hp9.cabbbcdeb:ehp9..

:p.
:dt.expression{m}
:dd.Matches exactly :hp9.m:ehp9. occurrences of what expression matches.
expression can be a single character or collating symbol or subexpression.
For example, :hp9.c{3}:ehp9. matches characters 5 through 7 of :hp9.ababccccd:ehp9.
(the first 3 :hp9.c:ehp9. characters only).

:p.
:dt.expression{m,}
:dd.Matches at least :hp9.m:ehp9. occurrences of what expression matches.
expression can be a single character or collating symbol or subexpression.
For example, :hp9.(ab){3,}:ehp9. matches :hp9.abababab:ehp9., but does not
match :hp9.ababac:ehp9..

:p.
:dt.expression{m,u}
:dd.Matches any number of occurrences, between :hp9.m:ehp9. and :hp9.u:ehp9.
inclusive, of what expression matches. expression can be a single character or
collating symbol or subexpression.
For example, :hp9.bc{1,3}:ehp9. matches characters 2 through 4 of
:hp9.abccd:ehp9. and characters 3 through 6 of :hp9.abbcccccd:ehp9..

:p.
:dt.^expression
:dd.Matches only sequences that match expression that start at the first
character of a string. For example, :hp9.^ab:ehp9. matches ab in the string
:hp9.abcdef:ehp9., but
does not match it in the string :hp9.cdefab:ehp9.. The expression can be the
entire :hp9.RE:ehp9. or any subexpression of it.

:p.
:dt.expression$
:dd.Matches only sequences that match expression that end the string.
For example, :hp9.ab$:ehp9. matches ab in the string :hp9.cdefab:ehp9. but
does not match it in the string :hp9.abcdef:ehp9.. The expression must be
the entire :hp9.RE:ehp9..

:p.
:dt.^expression$
:dd.Matches only an entire string. For example, :hp9.^abcde$:ehp9. matches
only :hp9.abcde:ehp9..
:edl.
  
:p.In addition to those listed above, you can also use the following
specifiers for :hp9.REs:ehp9.&colon.

:dl compact tsize=26.
:dt.expression+
:dd.Matches what one or more occurrences of expression matches.
For example, :hp9.a+(bc):ehp9. matches :hp9.aaaaabc:ehp9.;
:hp9.(bc)+:ehp9. matches characters 1 through 6 of :hp9.bcbcbcbb:ehp9..

:p.
:dt.expression?
:dd.Matches zero or one consecutive occurrences of what expression matches.
For example, :hp9.b?c:ehp9. matches character 2 of :hp9.acabbb:ehp9.
(zero occurrences of :hp9.b:ehp9. followed by :hp9.c:ehp9.).

:p.
:dt.expression|expression
:dd.Matches a string that matches either expression. For example,
:hp9.a((bc)|d):ehp9. matches both :hp9.abd:ehp9. and :hp9.ad:ehp9..
:edl.
  
:h2 id=regexOrder res=330.Order of precedence

:p.Like :hp9.C:ehp9. and :hp9.C++:ehp9. operators, the :hp9.RE:ehp9.
syntax specifiers are processed in a specific
order. The order of precedence for :hp9.REs:ehp9. is described below,
from highest to lowest. The specifiers in each category are also listed
in order of precedence.

:lm margin=15.
:table cols='30 27'.
:row.
:c.Collation-related bracket symbols
:c.[==]  [&colon.&colon.]  [..]
:row.
:c.Special characters
:c.\spec_char
:row.
:c.Bracket expressions
:c.[]
:row.
:c.Grouping
:c.()
:row.
:c.Repetition
:c.*  +  ?  {m}  {m,}  {m,n}
:row.
:c.Concetenation
:c.
:row.
:c.Anchoring
:c.^  $
:row.
:c.Alternation
:c.|
:etable.
:lm margin=15.
