📄 re_syntax.tex
字号:
% manual page source format generated by PolyglotMan v3.0.9,% available from http://polyglotman.sourceforge.net/\section{Syntax of the builtin regular expression library}\label{wxresyn}A {\it regular expression} describes strings of characters. It's apattern that matches certain strings and doesn't match others. \wxheading{See also}\helpref{wxRegEx}{wxregex}\subsection{Different Flavors of REs}\label{differentflavors}\helpref{Syntax of the builtin regular expression library}{wxresyn}Regular expressions (``RE''s), as defined by POSIX, come in twoflavors: {\it extended} REs (``EREs'') and {\it basic} REs (``BREs''). EREs are roughly thoseof the traditional {\it egrep}, while BREs are roughly those of the traditional {\it ed}. This implementation adds a third flavor, {\it advanced} REs (``AREs''), basicallyEREs with some significant extensions. This manual page primarily describesAREs. BREs mostly exist for backward compatibility in some old programs;they will be discussed at the \helpref{end}{wxresynbre}. POSIX EREs are almost an exact subsetof AREs. Features of AREs that are not present in EREs will be indicated.\subsection{Regular Expression Syntax}\label{resyntax}\helpref{Syntax of the builtin regular expression library}{wxresyn}These regular expressions are implemented usingthe package written by Henry Spencer, based on the 1003.2 spec and some(not quite all) of the Perl5 extensions (thanks, Henry!). Much of the descriptionof regular expressions below is copied verbatim from his manual entry. An ARE is one or more {\it branches}, separated by `{\bf $|$}', matching anything that matchesany of the branches. A branch is zero or more {\it constraints} or {\it quantifiedatoms}, concatenated. It matches a match for the first, followed by a matchfor the second, etc; an empty branch matches the empty string. A quantified atom is an {\it atom} possibly followed by a single {\it quantifier}. Without a quantifier,it matches a match for the atom. The quantifiers, and what a so-quantifiedatom matches, are:\begin{twocollist}\twocolwidtha{4cm}\twocolitem{{\bf *}}{a sequence of 0 or more matches of the atom}\twocolitem{{\bf +}}{a sequence of 1 or more matches of the atom}\twocolitem{{\bf ?}}{a sequence of 0 or 1 matches of the atom}\twocolitem{{\bf \{m\}}}{a sequence of exactly {\it m} matches of the atom}\twocolitem{{\bf \{m,\}}}{a sequence of {\it m} or more matches of the atom}\twocolitem{{\bf \{m,n\}}}{a sequence of {\it m} through {\it n} (inclusive)matches of the atom; {\it m} may not exceed {\it n}}\twocolitem{{\bf *? +? ?? \{m\}? \{m,\}? \{m,n\}?}}{{\it non-greedy} quantifiers,which match the same possibilities, but prefer thesmallest number rather than the largest number of matches (see \helpref{Matching}{wxresynmatching})}\end{twocollist}The forms using {\bf \{} and {\bf \}} are known as {\it bound}s. The numbers {\it m} and {\it n} are unsigneddecimal integers with permissible values from 0 to 255 inclusive. An atom is one of:\begin{twocollist}\twocolwidtha{4cm}\twocolitem{{\bf (re)}}{(where {\it re} is any regular expression) matches a match for {\it re}, with the match noted for possible reporting}\twocolitem{{\bf (?:re)}}{as previous, butdoes no reporting (a ``non-capturing'' set of parentheses)}\twocolitem{{\bf ()}}{matches an emptystring, noted for possible reporting}\twocolitem{{\bf (?:)}}{matches an empty string, without reporting}\twocolitem{{\bf $[chars]$}}{a {\it bracket expression}, matching any one of the {\it chars}(see \helpref{Bracket Expressions}{wxresynbracket} for more detail)}\twocolitem{{\bf .}}{matches any single character }\twocolitem{{\bf $\backslash$k}}{(where {\it k} is a non-alphanumeric character)matches that character taken as an ordinary character, e.g. $\backslash\backslash$ matches a backslashcharacter}\twocolitem{{\bf $\backslash$c}}{where {\it c} is alphanumeric (possibly followed by other characters),an {\it escape} (AREs only), see \helpref{Escapes}{wxresynescapes} below}\twocolitem{{\bf \{}}{when followed by a characterother than a digit, matches the left-brace character `{\bf \{}'; when followed bya digit, it is the beginning of a {\it bound} (see above)}\twocolitem{{\bf x}}{where {\it x} is a singlecharacter with no other significance, matches that character.}\end{twocollist}A {\it constraint} matches an empty string when specific conditions are met. A constraint maynot be followed by a quantifier. The simple constraints are as follows;some more constraints are described later, under \helpref{Escapes}{wxresynescapes}.\begin{twocollist}\twocolwidtha{4cm}\twocolitem{{\bf \caret}}{matches at the beginning of a line}\twocolitem{{\bf \$}}{matches at the end of a line}\twocolitem{{\bf (?=re)}}{{\it positive lookahead}(AREs only), matches at any point where a substring matching {\it re} begins}\twocolitem{{\bf (?!re)}}{{\it negative lookahead} (AREs only),matches at any point where no substring matching {\it re} begins}\end{twocollist}The lookahead constraints may not contain back references(see later), and all parentheses within them are considered non-capturing.An RE may not end with `{\bf $\backslash$}'.\subsection{Bracket Expressions}\label{wxresynbracket}\helpref{Syntax of the builtin regular expression library}{wxresyn}A {\it bracket expression} is a listof characters enclosed in `{\bf $[]$}'. It normally matches any single character fromthe list (but see below). If the list begins with `{\bf \caret}', it matches any singlecharacter (but see below) {\it not} from the rest of the list. If two charactersin the list are separated by `{\bf -}', this is shorthand for the full {\it range} ofcharacters between those two (inclusive) in the collating sequence, e.g. {\bf $[0-9]$} in ASCII matches any decimal digit. Two ranges may not share an endpoint,so e.g. {\bf a-c-e} is illegal. Ranges are very collating-sequence-dependent, and portableprograms should avoid relying on them. To include a literal {\bf $]$} or {\bf -} in thelist, the simplest method is to enclose it in {\bf $[.$} and {\bf $.]$} to make it a collatingelement (see below). Alternatively, make it the first character (followinga possible `{\bf \caret}'), or (AREs only) precede it with `{\bf $\backslash$}'.Alternatively, for `{\bf -}', makeit the last character, or the second endpoint of a range. To use a literal {\bf -} as the first endpoint of a range, make it a collating element or (AREsonly) precede it with `{\bf $\backslash$}'. With the exception of these, some combinations using {\bf $[$} (see next paragraphs), and escapes, all other special characters losetheir special significance within a bracket expression. Within a bracketexpression, a collating element (a character, a multi-character sequencethat collates as if it were a single character, or a collating-sequencename for either) enclosed in {\bf $[.$} and {\bf $.]$} stands for thesequence of characters of that collating element.{\it wxWidgets}: Currently no multi-character collating elements are defined.So in {\bf $[.X.]$}, {\it X} can either be a single character literal orthe name of a character. For example, the following are both identical {\bf $[[.0.]-[.9.]]$} and {\bf $[[.zero.]-[.nine.]]$} and mean the same as {\bf $[0-9]$}. See \helpref{Character Names}{wxresynchars}.%The sequence is a single element of the bracket%expression's list. A bracket expression in a locale that has multi-character%collating elements can thus match more than one character. So (insidiously),%a bracket expression that starts with {\bf \caret} can match multi-character collating%elements even if none of them appear in the bracket expression! ({\it Note:}%Tcl currently has no multi-character collating elements. This information%is only for illustration.) %%For example, assume the collating sequence includes%a {\bf ch} multi-character collating element. Then the RE {\bf $[[.ch.]]*c$} (zero or more% {\bf ch}'s followed by {\bf c}) matches the first five characters of `{\bf chchcc}'. Also, the%RE {\bf $[^c]b$} matches all of `{\bf chb}' (because {\bf $[^c]$} matches the multi-character {\bf ch}).Within a bracket expression, a collating element enclosed in {\bf $[=$} and {\bf $=]$}is an equivalence class, standing for the sequences of characters of allcollating elements equivalent to that one, including itself.%(If there are%no other equivalent collating elements, the treatment is as if the enclosing%delimiters were `{\bf $[.$}' and `{\bf $.]$}'.) For example, if {\bf o}%and {\bf \caret} are the members of an%equivalence class, then `{\bf $[[$=o=$]]$}', `{\bf $[[$=\caret=$]]$}',%and `{\bf $[o^]$}' are all synonymous.An equivalence class may not be an endpoint of a range.%({\it Note:} Tcl currently%implements only the Unicode locale. It doesn't define any equivalence classes.%The examples above are just illustrations.) {\it wxWidgets}: Currently no equivalence classes are defined, so {\bf $[=X=]$} stands for just the single character {\it X}. {\it X} can either be a single character literal or the name of a character,see \helpref{Character Names}{wxresynchars}.Within a bracket expression,the name of a {\it character class} enclosed in {\bf $[:$} and {\bf $:]$} stands for the listof all characters (not all collating elements!) belonging to that class.Standard character classes are:\begin{twocollist}\twocolwidtha{3cm}\twocolitem{{\bf alpha}}{A letter.}\twocolitem{{\bf upper}}{An upper-case letter.}\twocolitem{{\bf lower}}{A lower-case letter.}\twocolitem{{\bf digit}}{A decimal digit.}\twocolitem{{\bf xdigit}}{A hexadecimal digit.}\twocolitem{{\bf alnum}}{An alphanumeric (letter or digit).}\twocolitem{{\bf print}}{An alphanumeric (same as alnum).}\twocolitem{{\bf blank}}{A space or tab character.}\twocolitem{{\bf space}}{A character producing white space in displayed text.}\twocolitem{{\bf punct}}{A punctuation character.}\twocolitem{{\bf graph}}{A character with a visible representation.}\twocolitem{{\bf cntrl}}{A control character.}\end{twocollist}%A locale may provide others. (Note that the current Tcl%implementation has only one locale: the Unicode locale.)A character class may not be used as an endpoint of a range. {\it wxWidgets}: In a non-Unicode build, these character classifications depend on thecurrent locale, and correspond to the values return by the ANSI C 'is'functions: isalpha, isupper, etc. In Unicode mode they are based onUnicode classifications, and are not affected by the current locale.There are two special cases of bracket expressions:the bracket expressions {\bf $[[:$<$:]]$} and {\bf $[[:$>$:]]$} are constraints, matching emptystrings at the beginning and end of a word respectively. A word is definedas a sequence of word characters that is neither preceded nor followedby word characters. A word character is an {\it alnum} character or an underscore({\bf \_}). These special bracket expressions are deprecated; users of AREs shoulduse constraint escapes instead (see \helpref{Escapes}{wxresynescapes} below). \subsection{Escapes}\label{wxresynescapes}\helpref{Syntax of the builtin regular expression library}{wxresyn}Escapes (AREs only),which begin with a {\bf $\backslash$} followed by an alphanumeric character, come in several
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -