re_syntax.tex

来自「Wxpython Implemented on Windows CE, Sou」· TEX 代码 · 共 661 行 · 第 1/3 页

TEX
661
字号
% 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 a
pattern 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 two
flavors: {\it extended} REs (``EREs'') and {\it basic} REs (``BREs''). EREs are roughly those
of the traditional {\it egrep}, while BREs are roughly those of the traditional
 {\it ed}.  This implementation adds a third flavor, {\it advanced} REs (``AREs''), basically
EREs with some significant extensions. 

This manual page primarily describes
AREs. 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 subset
of 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 using
the 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 description
of regular expressions below is copied verbatim from his manual entry. 

An ARE is one or more {\it branches}, separated by `{\bf $|$}', matching anything that matches
any of the branches. 

A branch is zero or more {\it constraints} or {\it quantified
atoms}, concatenated. It matches a match for the first, followed by a match
for 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-quantified
atom 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 the
smallest 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 unsigned
decimal 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, but
does no reporting (a ``non-capturing'' set of parentheses)}
\twocolitem{{\bf ()}}{matches an empty
string, 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 backslash
character}
\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 character
other than a digit, matches the left-brace character `{\bf \{}'; when followed by
a digit, it is the beginning of a {\it bound} (see above)}
\twocolitem{{\bf x}}{where {\it x} is a single
character with no other significance, matches that character.}
\end{twocollist}

A {\it constraint} matches an empty string when specific conditions are met. A constraint may
not 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 list
of characters enclosed in `{\bf $[]$}'. It normally matches any single character from
the list (but see below). If the list begins with `{\bf \caret}', it matches any single
character (but see below) {\it not} from the rest of the list. 

If two characters
in the list are separated by `{\bf -}', this is shorthand for the full {\it range} of
characters 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 portable
programs should avoid relying on them. 

To include a literal {\bf $]$} or {\bf -} in the
list, the simplest method is to enclose it in {\bf $[.$} and {\bf $.]$} to make it a collating
element (see below). Alternatively, make it the first character (following
a possible `{\bf \caret}'), or (AREs only) precede it with `{\bf $\backslash$}'.
Alternatively, for `{\bf -}', make
it 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 (AREs
only) precede it with `{\bf $\backslash$}'. With the exception of these, some combinations using
 {\bf $[$} (see next paragraphs), and escapes, all other special characters lose
their special significance within a bracket expression. 

Within a bracket
expression, a collating element (a character, a multi-character sequence
that collates as if it were a single character, or a collating-sequence
name for either) enclosed in {\bf $[.$} and {\bf $.]$} stands for the
sequence 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 or
the 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 all
collating 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 list
of 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 the
current locale, and correspond to the values return by the ANSI C 'is'
functions: isalpha, isupper, etc. In Unicode mode they are based on
Unicode 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 empty
strings at the beginning and end of a word respectively.  A word is defined
as a sequence of word characters that is neither preceded nor followed
by word characters. A word character is an {\it alnum} character or an underscore
({\bf \_}). These special bracket expressions are deprecated; users of AREs should
use 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 + =
减小字号Ctrl + -
显示快捷键?