™.. PERLRE - Online Linux Manual PageSection : 1
Updated : 2009-02-12
Source : perl v5.10.1
Note : Perl Programmers Reference Guide
NAMEperlre − Perl regular expressions
DESCRIPTIONThis page describes the syntax of regular expressions in Perl. If you haven't used regular expressions before, a quick-start introduction is available in perlrequick, and a longer tutorial introduction is available in perlretut. For reference on how regular expressions are used in matching operations, plus various examples of the same, see discussions of \*(C`m//\*(C'\fR, \f(CW\*(C`s///\*(C'\fR, \f(CW\*(C`qr//\*(C'\fR and \f(CW\*(C`??\*(C'\fR in \*(L"Regexp Quote-Like Operators” in perlop.
ModifiersMatching operations can have various modifiers. Modifiers that relate to the interpretation of the regular expression inside are listed below. Modifiers that alter the way a regular expression is used by Perl are detailed in ‟Regexp Quote-Like Operators” in perlop and ‟Gory details of parsing quoted constructs” in perlop. m Treat string as multiple lines. That is, change ‟^” and ‟$” from matching the start or end of the string to matching the start or end of any line anywhere within the string. s Treat string as single line. That is, change ‟.” to match any character whatsoever, even a newline, which normally it would not match. Used together, as /ms, they let the ‟.” match any character whatsoever, while still allowing ‟^” and ‟$” to match, respectively, just after and just before newlines within the string. i Do case-insensitive pattern matching. If \*(C`use locale\*(C'\fR is in effect, the case map is taken from the current locale. See perllocale. x Extend your pattern's legibility by permitting whitespace and comments. p Preserve the string matched such that ${^PREMATCH}, {$^MATCH}, and ${^POSTMATCH} are available for use after matching. g and c Global matching, and keep the Current position after failed matching. Unlike i, m, s and x, these two flags affect the way the regex is used rather than the regex itself. See ‟Using regular expressions in Perl” in perlretut for further explanation of the g and c modifiers. These are usually written as "the \*(C`/x\*(C'\fR modifier", even though the delimiter in question might not really be a slash. Any of these modifiers may also be embedded within the regular expression itself using the \*(C`(?...)\*(C'\fR construct. See below. The \*(C`/x\*(C'\fR modifier itself needs a little more explanation. It tells the regular expression parser to ignore whitespace that is neither backslashed nor within a character class. You can use this to break up your regular expression into (slightly) more readable parts. The \*(C`#\*(C'\fR character is also treated as a metacharacter introducing a comment, just as in ordinary Perl code. This also means that if you want real whitespace or \*(C`#\*(C'\fR characters in the pattern (outside a character class, where they are unaffected by \*(C`/x\*(C'\fR), then you'll either have to escape them (using backslashes or \*(C`\eQ...\eE\*(C'\fR) or encode them using octal or hex escapes. Taken together, these features go a long way towards making Perl's regular expressions more readable. Note that you have to be careful not to include the pattern delimiter in the comment\*(--perl has no way of knowing you did not intend to close the pattern early. See the C−comment deletion code in perlop. Also note that anything inside a \*(C`\eQ...\eE\*(C'\fR stays unaffected by \f(CW\*(C`/x\*(C'\fR.
Regular ExpressionsMetacharacters The patterns used in Perl pattern matching evolved from those supplied in the Version 8 regex routines. (The routines are derived (distantly) from Henry Spencer's freely redistributable reimplementation of the V8 routines.) See ‟Version 8 Regular Expressions” for details. In particular the following metacharacters have their standard egrep−ish meanings: \ Quote the next metacharacter
^ Match the beginning of the line
. Match any character (except newline)
$ Match the end of the line (or before newline at the end)
| Alternation
() Grouping
[] Character class
By default, the ‟^” character is guaranteed to match only the beginning of the string, the ‟$” character only the end (or before the newline at the end), and Perl does certain optimizations with the assumption that the string contains only one line. Embedded newlines will not be matched by ‟^” or ‟$”. You may, however, wish to treat a string as a multi-line buffer, such that the ‟^” will match after any newline within the string (except if the newline is the last character in the string), and ‟$” will match before any newline. At the cost of a little more overhead, you can do this by using the /m modifier on the pattern match operator. (Older programs did this by setting $*, but this practice has been removed in perl 5.9.) To simplify multi-line substitutions, the ‟.” character never matches a newline unless you use the \*(C`/s\*(C'\fR modifier, which in effect tells Perl to pretend the string is a single line\*(--even if it isn't. Quantifiers The following standard quantifiers are recognized: * Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
(If a curly bracket occurs in any other context, it is treated as a regular character. In particular, the lower bound is not optional.) The ‟*” quantifier is equivalent to \*(C`{0,}\*(C'\fR, the \*(L"+\*(R" quantifier to \*(C`{1,}\*(C'\fR, and the \*(L"?\*(R" quantifier to \f(CW\*(C`{0,1}\*(C'\fR. n and m are limited to integral values less than a preset limit defined when perl is built. This is usually 32766 on the most common platforms. The actual limit can be seen in the error message generated by code such as this: $_ **= $_ , / {$_} / for 2 .. 42;
By default, a quantified subpattern is ‟greedy”, that is, it will match as many times as possible (given a particular starting location) while still allowing the rest of the pattern to match. If you want it to match the minimum number of times possible, follow the quantifier with a ‟?”. Note that the meanings don't change, just the ‟greediness”: *? Match 0 or more times, not greedily
+? Match 1 or more times, not greedily
?? Match 0 or 1 time, not greedily
{n}? Match exactly n times, not greedily
{n,}? Match at least n times, not greedily
{n,m}? Match at least n but not more than m times, not greedily
By default, when a quantified subpattern does not allow the rest of the overall pattern to match, Perl will backtrack. However, this behaviour is sometimes undesirable. Thus Perl provides the ‟possessive” quantifier form as well. *+ Match 0 or more times and give nothing back
++ Match 1 or more times and give nothing back
?+ Match 0 or 1 time and give nothing back
{n}+ Match exactly n times and give nothing back (redundant)
{n,}+ Match at least n times and give nothing back
{n,m}+ Match at least n but not more than m times and give nothing back
For instance, 'aaaa' =~ /a++a/
will never match, as the \*(C`a++\*(C'\fR will gobble up all the \f(CW\*(C`a\*(C'\fR's in the string and won't leave any for the remaining part of the pattern. This feature can be extremely useful to give perl hints about where it shouldn't backtrack. For instance, the typical ‟match a double-quoted string” problem can be most efficiently performed when written as: /"(?:[^"\\]++|\\.)*+"/
as we know that if the final quote does not match, backtracking will not help. See the independent subexpression \*(C`(?>...)\*(C'\fR for more details; possessive quantifiers are just syntactic sugar for that construct. For instance the above example could also be written as follows: /"(?>(?:(?>[^"\\]+)|\\.)*)"/
Escape sequences Because patterns are processed as double quoted strings, the following also work: \t tab (HT, TAB)
\n newline (LF, NL)
\r return (CR)
\f form feed (FF)
\a alarm (bell) (BEL)
\e escape (think troff) (ESC)
\033 octal char (example: ESC)
\x1B hex char (example: ESC)
\x{263a} long hex char (example: Unicode SMILEY)
\cK control char (example: VT)
\N{name} named Unicode character
\l lowercase next char (think vi)
\u uppercase next char (think vi)
\L lowercase till \E (think vi)
\U uppercase till \E (think vi)
\E end case modification (think vi)
\Q quote (disable) pattern metacharacters till \E
If \*(C`use locale\*(C'\fR is in effect, the case map used by \f(CW\*(C`\el\*(C'\fR, \f(CW\*(C`\eL\*(C'\fR, \f(CW\*(C`\eu\*(C'\fR and \*(C`\eU\*(C'\fR is taken from the current locale. See perllocale. For documentation of \*(C`\eN{name}\*(C'\fR, see charnames. You cannot include a literal \*(C`$\*(C'\fR or \f(CW\*(C`@\*(C'\fR within a \f(CW\*(C`\eQ\*(C'\fR sequence. An unescaped \*(C`$\*(C'\fR or \f(CW\*(C`@\*(C'\fR interpolates the corresponding variable, while escaping will cause the literal string \*(C`\e$\*(C'\fR to be matched. You'll need to write something like \*(C`m/\eQuser\eE\e@\eQhost/\*(C'\fR. Character Classes and other Special Escapes In addition, Perl defines the following: \w Match a "word" character (alphanumeric plus "_")
\W Match a non−"word" character
\s Match a whitespace character
\S Match a non−whitespace character
\d Match a digit character
\D Match a non−digit character
\pP Match P, named property. Use \p{Prop} for longer names.
\PP Match non−P
\X Match eXtended Unicode "combining character sequence",
equivalent to (?>\PM\pM*)
\C Match a single C char (octet) even under Unicode.
NOTE: breaks up characters into their UTF−8 bytes,
so you may end up with malformed pieces of UTF−8.
Unsupported in lookbehind.
\1 Backreference to a specific group.
'1' may actually be any positive integer.
\g1 Backreference to a specific or previous group,
\g{−1} number may be negative indicating a previous buffer and may
optionally be wrapped in curly brackets for safer parsing.
\g{name} Named backreference
\k<name> Named backreference
\K Keep the stuff left of the \K, don't include it in $&
\v Vertical whitespace
\V Not vertical whitespace
\h Horizontal whitespace
\H Not horizontal whitespace
\R Linebreak
A \*(C`\ew\*(C'\fR matches a single alphanumeric character (an alphabetic character, or a decimal digit) or \*(C`_\*(C'\fR, not a whole word. Use \f(CW\*(C`\ew+\*(C'\fR to match a string of Perl-identifier characters (which isn't the same as matching an English word). If \*(C`use locale\*(C'\fR is in effect, the list of alphabetic characters generated by \*(C`\ew\*(C'\fR is taken from the current locale. See perllocale. You may use \*(C`\ew\*(C'\fR, \f(CW\*(C`\eW\*(C'\fR, \f(CW\*(C`\es\*(C'\fR, \f(CW\*(C`\eS\*(C'\fR, \*(C`\ed\*(C'\fR, and \f(CW\*(C`\eD\*(C'\fR within character classes, but they aren't usable as either end of a range. If any of them precedes or follows a ‟−”, the ‟−” is understood literally. If Unicode is in effect, \*(C`\es\*(C'\fR matches also ‟\x{85}”, ‟\x{2028}”, and ‟\x{2029}”. See perlunicode for more details about \*(C`\epP\*(C'\fR, \f(CW\*(C`\ePP\*(C'\fR, \f(CW\*(C`\eX\*(C'\fR and the possibility of defining your own \*(C`\ep\*(C'\fR and \f(CW\*(C`\eP\*(C'\fR properties, and perluniintro about Unicode in general. \*(C`\eR\*(C'\fR will atomically match a linebreak, including the network line-ending ‟\x0D\x0A”. Specifically, is exactly equivalent to (?>\x0D\x0A?|[\x0A−\x0C\x85\x{2028}\x{2029}])
Note: \*(C`\eR\*(C'\fR has no special meaning inside of a character class; use \*(C`\ev\*(C'\fR instead (vertical whitespace). The POSIX character class syntax [:class:]
is also available. Note that the \*(C`[\*(C'\fR and \f(CW\*(C`]\*(C'\fR brackets are \fIliteral\fR; they must always be used within a character class expression. # this is correct:
$string =~ /[[:alpha:]]/;
# this is not, and will generate a warning:
$string =~ /[:alpha:]/;
The available classes and their backslash equivalents (if available) are as follows: alpha
alnum
ascii
blank [1]
cntrl
digit \d
graph
lower
print
punct
space \s [2]
upper
word \w [3]
xdigit
[1] A GNU extension equivalent to \*(C`[ \et]\*(C'\fR, \*(L"all horizontal whitespace\*(R". [2] Not exactly equivalent to \*(C`\es\*(C'\fR since the \f(CW\*(C`[[:space:]]\*(C'\fR includes also the (very rare) ‟vertical tabulator”, ‟\cK” or chr(11) in ASCII. [3] A Perl extension, see above. For example use \*(C`[:upper:]\*(C'\fR to match all the uppercase characters. Note that the \*(C`[]\*(C'\fR are part of the \f(CW\*(C`[::]\*(C'\fR construct, not part of the whole character class. For example: [01[:alpha:]%]
matches zero, one, any alphabetic character, and the percent sign. The following equivalences to Unicode \p{} constructs and equivalent backslash character classes (if available), will hold: [[:...:]] \p{...} backslash
alpha IsAlpha
alnum IsAlnum
ascii IsASCII
blank
cntrl IsCntrl
digit IsDigit \d
graph IsGraph
lower IsLower
print IsPrint (but see [2] below)
punct IsPunct (but see [3] below)
space IsSpace
IsSpacePerl \s
upper IsUpper
word IsWord \w
xdigit IsXDigit
For example \*(C`[[:lower:]]\*(C'\fR and \f(CW\*(C`\ep{IsLower}\*(C'\fR are equivalent. However, the equivalence between \*(C`[[:xxxxx:]]\*(C'\fR and \f(CW\*(C`\ep{IsXxxxx}\*(C'\fR is not exact. [1] If the \*(C`utf8\*(C'\fR pragma is not used but the \f(CW\*(C`locale\*(C'\fR pragma is, the classes correlate with the usual isalpha (3) interface (except for ‟word” and ‟blank”). But if the \*(C`locale\*(C'\fR or \f(CW\*(C`encoding\*(C'\fR pragmas are not used and the string is not \*(C`utf8\*(C'\fR, then \f(CW\*(C`[[:xxxxx:]]\*(C'\fR (and \f(CW\*(C`\ew\*(C'\fR, etc.) will not match characters 0x80−0xff; whereas \*(C`\ep{IsXxxxx}\*(C'\fR will force the string to \*(C`utf8\*(C'\fR and can match these characters (as Unicode). [2] \*(C`\ep{IsPrint}\*(C'\fR matches characters 0x09\-0x0d but \f(CW\*(C`[[:print:]]\*(C'\fR does not. [3] \*(C`[[:punct::]]\*(C'\fR matches the following but \f(CW\*(C`\ep{IsPunct}\*(C'\fR does not, because they are classed as symbols (not punctuation) in Unicode. $ Currency symbol + < = > | ~ Mathematical symbols ^ ` Modifier symbols (accents) The other named classes are: cntrl Any control character. Usually characters that don't produce output as such but instead control the terminal somehow: for example newline and backspace are control characters. All characters with ord() less than 32 are usually classified as control characters (assuming ASCII, the ISO Latin character sets, and Unicode), as is the character with the ord() value of 127 (\*(C`DEL\*(C'\fR). graph Any alphanumeric or punctuation (special) character. print Any alphanumeric or punctuation (special) character or the space character. punct Any punctuation (special) character. xdigit Any hexadecimal digit. Though this may feel silly ([0−9A−Fa−f] would work just fine) it is included for completeness. You can negate the [::] character classes by prefixing the class name with a '^'. This is a Perl extension. For example: POSIX traditional Unicode
[[:^digit:]] \D \P{IsDigit}
[[:^space:]] \S \P{IsSpace}
[[:^word:]] \W \P{IsWord}
Perl respects the POSIX standard in that POSIX character classes are only supported within a character class. The POSIX character classes [.cc.] and [=cc=] are recognized but not supported and trying to use them will cause an error. Assertions Perl defines the following zero-width assertions: \b Match a word boundary
\B Match except at a word boundary
\A Match only at beginning of string
\Z Match only at end of string, or before newline at the end
\z Match only at end of string
\G Match only at pos() (e.g. at the end−of−match position
of prior m//g)
A word boundary (\*(C`\eb\*(C'\fR) is a spot between two characters that has a \*(C`\ew\*(C'\fR on one side of it and a \f(CW\*(C`\eW\*(C'\fR on the other side of it (in either order), counting the imaginary characters off the beginning and end of the string as matching a \*(C`\eW\*(C'\fR. (Within character classes \*(C`\eb\*(C'\fR represents backspace rather than a word boundary, just as it normally does in any double-quoted string.) The \*(C`\eA\*(C'\fR and \f(CW\*(C`\eZ\*(C'\fR are just like \*(L"^\*(R" and \*(L"$\*(R", except that they won't match multiple times when the \*(C`/m\*(C'\fR modifier is used, while ‟^” and ‟$” will match at every internal line boundary. To match the actual end of the string and not ignore an optional trailing newline, use \*(C`\ez\*(C'\fR. The \*(C`\eG\*(C'\fR assertion can be used to chain global matches (using \*(C`m//g\*(C'\fR), as described in \*(L"Regexp Quote-Like Operators\*(R" in perlop. It is also useful when writing \*(C`lex\*(C'\fR\-like scanners, when you have several patterns that you want to match against consequent substrings of your string, see the previous reference. The actual location where \*(C`\eG\*(C'\fR will match can also be influenced by using \f(CW\*(C`pos()\*(C'\fR as an lvalue: see ‟pos” in perlfunc. Note that the rule for zero-length matches is modified somewhat, in that contents to the left of \*(C`\eG\*(C'\fR is not counted when determining the length of the match. Thus the following will not match forever: $str = 'ABC';
pos($str) = 1;
while (/.\G/g) {
print $&;
}
It will print 'A' and then terminate, as it considers the match to be zero-width, and thus will not match at the same position twice in a row. It is worth noting that \*(C`\eG\*(C'\fR improperly used can result in an infinite loop. Take care when using patterns that include \*(C`\eG\*(C'\fR in an alternation. Capture buffers The bracketing construct \*(C`( ... )\*(C'\fR creates capture buffers. To refer to the current contents of a buffer later on, within the same pattern, use \1 for the first, \2 for the second, and so on. Outside the match use ‟$” instead of ‟\”. (The \<digit> notation works in certain circumstances outside the match. See the warning below about \1 vs $1 for details.) Referring back to another part of the match is called a backreference. There is no limit to the number of captured substrings that you may use. However Perl also uses \10, \11, etc. as aliases for \010, \011, etc. (Recall that 0 means octal, so \011 is the character at number 9 in your coded character set; which would be the 10th character, a horizontal tab under ASCII.) Perl resolves this ambiguity by interpreting \10 as a backreference only if at least 10 left parentheses have opened before it. Likewise \11 is a backreference only if at least 11 left parentheses have opened before it. And so on. \1 through \9 are always interpreted as backreferences. In order to provide a safer and easier way to construct patterns using backreferences, Perl provides the \*(C`\eg{N}\*(C'\fR notation (starting with perl 5.10.0). The curly brackets are optional, however omitting them is less safe as the meaning of the pattern can be changed by text (such as digits) following it. When N is a positive integer the \*(C`\eg{N}\*(C'\fR notation is exactly equivalent to using normal backreferences. When N is a negative integer then it is a relative backreference referring to the previous N'th capturing group. When the bracket form is used and N is not an integer, it is treated as a reference to a named buffer. Thus \*(C`\eg{\-1}\*(C'\fR refers to the last buffer, \f(CW\*(C`\eg{\-2}\*(C'\fR refers to the buffer before that. For example: /
(Y) # buffer 1
( # buffer 2
(X) # buffer 3
\g{−1} # backref to buffer 3
\g{−3} # backref to buffer 1
)
/x
and would match the same as \*(C`/(Y) ( (X) \e3 \e1 )/x\*(C'\fR. Additionally, as of Perl 5.10.0 you may use named capture buffers and named backreferences. The notation is \*(C`(?<name>...)\*(C'\fR to declare and \f(CW\*(C`\ek<name>\*(C'\fR to reference. You may also use apostrophes instead of angle brackets to delimit the name; and you may use the bracketed \*(C`\eg{name}\*(C'\fR backreference syntax. It's possible to refer to a named capture buffer by absolute and relative number as well. Outside the pattern, a named capture buffer is available via the \*(C`%+\*(C'\fR hash. When different buffers within the same pattern have the same name, $+{name} and \*(C`\ek<name>\*(C'\fR refer to the leftmost defined group. (Thus it's possible to do things with named capture buffers that would otherwise require \*(C`(??{})\*(C'\fR code to accomplish.) Examples: s/^([^ ]*) *([^ ]*)/$2 $1/; # swap first two words
/(.)\1/ # find first doubled char
and print "'$1' is the first doubled character\n";
/(?<char>.)\k<char>/ # ... a different way
and print "'$+{char}' is the first doubled character\n";
/(?'char'.)\1/ # ... mix and match
and print "'$1' is the first doubled character\n";
if (/Time: (..):(..):(..)/) { # parse out values
$hours = $1;
$minutes = $2;
$seconds = $3;
}
Several special variables also refer back to portions of the previous match. $+ returns whatever the last bracket match matched. $& returns the entire matched string. (At one point $0 did also, but now it returns the name of the program.) \*(C`$\`\*(C'\fR returns everything before the matched string. \*(C`$\*(Aq\*(C'\fR returns everything after the matched string. And $^N contains whatever was matched by the most-recently closed group (submatch). $^N can be used in extended patterns (see below), for example to assign a submatch to a variable. The numbered match variables ($1, $2, $3, etc.) and the related punctuation set ($+, $&, \*(C`$\`\*(C'\fR, \f(CW\*(C`$\*(Aq\*(C'\fR, and \f(CW$^N\fR) are all dynamically scoped until the end of the enclosing block or until the next successful match, whichever comes first. (See ‟Compound Statements” in perlsyn.) NOTE: Failed matches in Perl do not reset the match variables, which makes it easier to write code that tests for a series of more specific cases and remembers the best match. WARNING: Once Perl sees that you need one of $&, \*(C`$\`\*(C'\fR, or \*(C`$\*(Aq\*(C'\fR anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Perl uses the same mechanism to produce $1, $2, etc, so you also pay a price for each pattern that contains capturing parentheses. (To avoid this cost while retaining the grouping behaviour, use the extended regular expression \*(C`(?: ... )\*(C'\fR instead.) But if you never use $&, \*(C`$\`\*(C'\fR or \f(CW\*(C`$\*(Aq\*(C'\fR, then patterns \fIwithout\fR capturing parentheses will not be penalized. So avoid $&, \*(C`$\*(Aq\*(C'\fR, and \f(CW\*(C`$\`\*(C'\fR if you can, but if you can't (and some algorithms really appreciate them), once you've used them once, use them at will, because you've already paid the price. As of 5.005, $& is not so costly as the other two. As a workaround for this problem, Perl 5.10.0 introduces \*(C`${^PREMATCH}\*(C'\fR, \*(C`${^MATCH}\*(C'\fR and \f(CW\*(C`${^POSTMATCH}\*(C'\fR, which are equivalent to \f(CW\*(C`$\`\*(C'\fR, \f(CW$&\fR and \*(C`$\*(Aq\*(C'\fR, \fBexcept\fR that they are only guaranteed to be defined after a successful match that was executed with the \*(C`/p\*(C'\fR (preserve) modifier. The use of these variables incurs no global performance penalty, unlike their punctuation char equivalents, however at the trade-off that you have to tell perl when you want to use them. Backslashed metacharacters in Perl are alphanumeric, such as \*(C`\eb\*(C'\fR, \*(C`\ew\*(C'\fR, \f(CW\*(C`\en\*(C'\fR. Unlike some other regular expression languages, there are no backslashed symbols that aren't alphanumeric. So anything that looks like \\, \(, \), \<, \>, \{, or \} is always interpreted as a literal character, not a metacharacter. This was once used in a common idiom to disable or quote the special meanings of regular expression metacharacters in a string that you want to use for a pattern. Simply quote all non−‟word” characters: $pattern =~ s/(\W)/\\$1/g;
(If \*(C`use locale\*(C'\fR is set, then this depends on the current locale.) Today it is more common to use the quotemeta() function or the \*(C`\eQ\*(C'\fR metaquoting escape sequence to disable all metacharacters' special meanings like this: /$unquoted\Q$quoted\E$unquoted/
Beware that if you put literal backslashes (those not inside interpolated variables) between \*(C`\eQ\*(C'\fR and \f(CW\*(C`\eE\*(C'\fR, double-quotish backslash interpolation may lead to confusing results. If you need to use literal backslashes within \*(C`\eQ...\eE\*(C'\fR, consult ‟Gory details of parsing quoted constructs” in perlop.
Extended PatternsPerl also defines a consistent extension syntax for features not found in standard tools like awk and lex. The syntax is a pair of parentheses with a question mark as the first thing within the parentheses. The character after the question mark indicates the extension. The stability of these extensions varies widely. Some have been part of the core language for many years. Others are experimental and may change without warning or be completely removed. Check the documentation on an individual feature to verify its current status. A question mark was chosen for this and for the minimal-matching construct because 1) question marks are rare in older regular expressions, and 2) whenever you see one, you should stop and ‟question” exactly what is going on. That's psychology... (?#text) A comment. The text is ignored. If the \*(C`/x\*(C'\fR modifier enables whitespace formatting, a simple \*(C`#\*(C'\fR will suffice. Note that Perl closes the comment as soon as it sees a \*(C`)\*(C'\fR, so there is no way to put a literal \*(C`)\*(C'\fR in the comment. (?pimsx−imsx) One or more embedded pattern-match modifiers, to be turned on (or turned off, if preceded by \*(C`\-\*(C'\fR) for the remainder of the pattern or the remainder of the enclosing pattern group (if any). This is particularly useful for dynamic patterns, such as those read in from a configuration file, taken from an argument, or specified in a table somewhere. Consider the case where some patterns want to be case sensitive and some do not: The case insensitive ones merely need to include \*(C`(?i)\*(C'\fR at the front of the pattern. For example: $pattern = "foobar";
if ( /$pattern/i ) { }
# more flexible:
$pattern = "(?i)foobar";
if ( /$pattern/ ) { }
These modifiers are restored at the end of the enclosing group. For example, ( (?i) blah ) \s+ \1
will match \*(C`blah\*(C'\fR in any case, some spaces, and an exact (\fIincluding the case\fR!) repetition of the previous word, assuming the \*(C`/x\*(C'\fR modifier, and no \f(CW\*(C`/i\*(C'\fR modifier outside this group. Note that the \*(C`p\*(C'\fR modifier is special in that it can only be enabled, not disabled, and that its presence anywhere in a pattern has a global effect. Thus \*(C`(?\-p)\*(C'\fR and \f(CW\*(C`(?\-p:...)\*(C'\fR are meaningless and will warn when executed under \*(C`use warnings\*(C'\fR. (?:pattern) (?imsx−imsx:pattern) This is for clustering, not capturing; it groups subexpressions like ‟()”, but doesn't make backreferences as ‟()” does. So @fields = split(/\b(?:a|b|c)\b/)
is like @fields = split(/\b(a|b|c)\b/)
but doesn't spit out extra fields. It's also cheaper not to capture characters if you don't need to. Any letters between \*(C`?\*(C'\fR and \f(CW\*(C`:\*(C'\fR act as flags modifiers as with \*(C`(?imsx\-imsx)\*(C'\fR. For example, /(?s−i:more.*than).*million/i
is equivalent to the more verbose /(?:(?s−i)more.*than).*million/i
(?|pattern) This is the ‟branch reset” pattern, which has the special property that the capture buffers are numbered from the same starting point in each alternation branch. It is available starting from perl 5.10.0. Capture buffers are numbered from left to right, but inside this construct the numbering is restarted for each branch. The numbering within each branch will be as normal, and any buffers following this construct will be numbered as though the construct contained only one branch, that being the one with the most capture buffers in it. This construct will be useful when you want to capture one of a number of alternative matches. Consider the following pattern. The numbers underneath show in which buffer the captured content will be stored. # before −−−−−−−−−−−−−−−branch−reset−−−−−−−−−−− after
/ ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
# 1 2 2 3 2 3 4
Note: as of Perl 5.10.0, branch resets interfere with the contents of the \*(C`%+\*(C'\fR hash, that holds named captures. Consider using \f(CW\*(C`%\-\*(C'\fR instead. Look-Around Assertions Look-around assertions are zero width patterns which match a specific pattern without including it in $&. Positive assertions match when their subpattern matches, negative assertions match when their subpattern fails. Look-behind matches text up to the current match position, look-ahead matches text following the current match position. (?=pattern) A zero-width positive look-ahead assertion. For example, \*(C`/\ew+(?=\et)/\*(C'\fR matches a word followed by a tab, without including the tab in $&. (?!pattern) A zero-width negative look-ahead assertion. For example \*(C`/foo(?!bar)/\*(C'\fR matches any occurrence of ‟foo” that isn't followed by ‟bar”. Note however that look-ahead and look-behind are NOT the same thing. You cannot use this for look-behind. If you are looking for a ‟bar” that isn't preceded by a ‟foo”, \*(C`/(?!foo)bar/\*(C'\fR will not do what you want. That's because the \*(C`(?!foo)\*(C'\fR is just saying that the next thing cannot be ‟foo”−−and it's not, it's a ‟bar”, so ‟foobar” will match. You would have to do something like \*(C`/(?!foo)...bar/\*(C'\fR for that. We say ‟like” because there's the case of your ‟bar” not having three characters before it. You could cover that this way: \*(C`/(?:(?!foo)...|^.{0,2})bar/\*(C'\fR. Sometimes it's still easier just to say: if (/bar/ && $` !~ /foo$/)
For look-behind see below. (?<=pattern) \K A zero-width positive look-behind assertion. For example, \*(C`/(?<=\et)\ew+/\*(C'\fR matches a word that follows a tab, without including the tab in $&. Works only for fixed-width look-behind. There is a special form of this construct, called \*(C`\eK\*(C'\fR, which causes the regex engine to ‟keep” everything it had matched prior to the \*(C`\eK\*(C'\fR and not include it in $&. This effectively provides variable length look-behind. The use of \*(C`\eK\*(C'\fR inside of another look-around assertion is allowed, but the behaviour is currently not well defined. For various reasons \*(C`\eK\*(C'\fR may be significantly more efficient than the equivalent \*(C`(?<=...)\*(C'\fR construct, and it is especially useful in situations where you want to efficiently remove something following something else in a string. For instance s/(foo)bar/$1/g;
can be rewritten as the much more efficient s/foo\Kbar//g;
(?<!pattern) A zero-width negative look-behind assertion. For example \*(C`/(?<!bar)foo/\*(C'\fR matches any occurrence of ‟foo” that does not follow ‟bar”. Works only for fixed-width look-behind. (?'NAME'pattern) (?<NAME>pattern) A named capture buffer. Identical in every respect to normal capturing parentheses \*(C`()\*(C'\fR but for the additional fact that \f(CW\*(C`%+\*(C'\fR or \f(CW\*(C`%\-\*(C'\fR may be used after a successful match to refer to a named buffer. See \*(C`perlvar\*(C'\fR for more details on the \*(C`%+\*(C'\fR and \f(CW\*(C`%\-\*(C'\fR hashes. If multiple distinct capture buffers have the same name then the $+{NAME} will refer to the leftmost defined buffer in the match. The forms \*(C`(?\*(AqNAME\*(Aqpattern)\*(C'\fR and \f(CW\*(C`(?<NAME>pattern)\*(C'\fR are equivalent. NOTE: While the notation of this construct is the same as the similar function in .NET regexes, the behavior is not. In Perl the buffers are numbered sequentially regardless of being named or not. Thus in the pattern /(x)(?<foo>y)(z)/
$+{foo} will be the same as $2, and $3 will contain 'z' instead of the opposite which is what a .NET regex hacker might expect. Currently NAME is restricted to simple identifiers only. In other words, it must match \*(C`/^[_A\-Za\-z][_A\-Za\-z0\-9]*\ez/\*(C'\fR or its Unicode extension (see utf8), though it isn't extended by the locale (see perllocale). NOTE: In order to make things easier for programmers with experience with the Python or PCRE regex engines, the pattern \*(C`(?PE<lt>NAMEE<gt>pattern)\*(C'\fR may be used instead of \*(C`(?<NAME>pattern)\*(C'\fR; however this form does not support the use of single quotes as a delimiter for the name. \k<NAME> \k'NAME' Named backreference. Similar to numeric backreferences, except that the group is designated by name and not number. If multiple groups have the same name then it refers to the leftmost defined group in the current match. It is an error to refer to a name not defined by a \*(C`(?<NAME>)\*(C'\fR earlier in the pattern. Both forms are equivalent. NOTE: In order to make things easier for programmers with experience with the Python or PCRE regex engines, the pattern \*(C`(?P=NAME)\*(C'\fR may be used instead of \*(C`\ek<NAME>\*(C'\fR. (?{ code }) WARNING: This extended regular expression feature is considered experimental, and may be changed without notice. Code executed that has side effects may not perform identically from version to version due to the effect of future optimisations in the regex engine. This zero-width assertion evaluates any embedded Perl code. It always succeeds, and its \*(C`code\*(C'\fR is not interpolated. Currently, the rules to determine where the \*(C`code\*(C'\fR ends are somewhat convoluted. This feature can be used together with the special variable $^N to capture the results of submatches in variables without having to keep track of the number of nested parentheses. For example: $_ = "The brown fox jumps over the lazy dog";
/the (\S+)(?{ $color = $^N }) (\S+)(?{ $animal = $^N })/i;
print "color = $color, animal = $animal\n";
Inside the \*(C`(?{...})\*(C'\fR block, \f(CW$_\fR refers to the string the regular expression is matching against. You can also use \*(C`pos()\*(C'\fR to know what is the current position of matching within this string. The \*(C`code\*(C'\fR is properly scoped in the following sense: If the assertion is backtracked (compare ‟Backtracking”), all changes introduced after \*(C`local\*(C'\fRization are undone, so that $_ = 'a' x 8;
m<
(?{ $cnt = 0 }) # Initialize $cnt.
(
a
(?{
local $cnt = $cnt + 1; # Update $cnt, backtracking−safe.
})
)*
aaaa
(?{ $res = $cnt }) # On success copy to non−localized
# location.
>x;
will set \*(C`$res = 4\*(C'\fR. Note that after the match, \f(CW$cnt\fR returns to the globally introduced value, because the scopes that restrict \*(C`local\*(C'\fR operators are unwound. This assertion may be used as a \*(C`(?(condition)yes\-pattern|no\-pattern)\*(C'\fR switch. If not used in this way, the result of evaluation of \*(C`code\*(C'\fR is put into the special variable \f(CW$^R\fR. This happens immediately, so $^R can be used from other \*(C`(?{ code })\*(C'\fR assertions inside the same regular expression. The assignment to $^R above is properly localized, so the old value of $^R is restored if the assertion is backtracked; compare ‟Backtracking”. Due to an unfortunate implementation issue, the Perl code contained in these blocks is treated as a compile time closure that can have seemingly bizarre consequences when used with lexically scoped variables inside of subroutines or loops. There are various workarounds for this, including simply using global variables instead. If you are using this construct and strange results occur then check for the use of lexically scoped variables. For reasons of security, this construct is forbidden if the regular expression involves run-time interpolation of variables, unless the perilous \*(C`use re \*(Aqeval\*(Aq\*(C'\fR pragma has been used (see re), or the variables contain results of \*(C`qr//\*(C'\fR operator (see ‟qr/STRING/imosx” in perlop). This restriction is due to the wide-spread and remarkably convenient custom of using run-time determined strings as patterns. For example: $re = <>;
chomp $re;
$string =~ /$re/;
Before Perl knew how to execute interpolated code within a pattern, this operation was completely safe from a security point of view, although it could raise an exception from an illegal pattern. If you turn on the \*(C`use re \*(Aqeval\*(Aq\*(C'\fR, though, it is no longer secure, so you should only do so if you are also using taint checking. Better yet, use the carefully constrained evaluation within a Safe compartment. See perlsec for details about both these mechanisms. Because Perl's regex engine is currently not re-entrant, interpolated code may not invoke the regex engine either directly with \*(C`m//\*(C'\fR or \f(CW\*(C`s///\*(C'\fR), or indirectly with functions such as \*(C`split\*(C'\fR. (??{ code }) WARNING: This extended regular expression feature is considered experimental, and may be changed without notice. Code executed that has side effects may not perform identically from version to version due to the effect of future optimisations in the regex engine. This is a ‟postponed” regular subexpression. The \*(C`code\*(C'\fR is evaluated at run time, at the moment this subexpression may match. The result of evaluation is considered as a regular expression and matched as if it were inserted instead of this construct. Note that this means that the contents of capture buffers defined inside an eval'ed pattern are not available outside of the pattern, and vice versa, there is no way for the inner pattern to refer to a capture buffer defined outside. Thus, ('a' x 100)=~/(??{'(.)' x 100})/
will match, it will not set $1. The \*(C`code\*(C'\fR is not interpolated. As before, the rules to determine where the \*(C`code\*(C'\fR ends are currently somewhat convoluted. The following pattern matches a parenthesized group: $re = qr{
\(
(?:
(?> [^()]+ ) # Non−parens without backtracking
|
(??{ $re }) # Group with matching parens
)*
\)
}x;
See also \*(C`(?PARNO)\*(C'\fR for a different, more efficient way to accomplish the same task. Because perl's regex engine is not currently re-entrant, delayed code may not invoke the regex engine either directly with \*(C`m//\*(C'\fR or \f(CW\*(C`s///\*(C'\fR), or indirectly with functions such as \*(C`split\*(C'\fR. Recursing deeper than 50 times without consuming any input string will result in a fatal error. The maximum depth is compiled into perl, so changing it requires a custom build. (?PARNO) (?−PARNO) (?+PARNO) (?R) (?0) Similar to \*(C`(??{ code })\*(C'\fR except it does not involve compiling any code, instead it treats the contents of a capture buffer as an independent pattern that must match at the current position. Capture buffers contained by the pattern will have the value as determined by the outermost recursion. PARNO is a sequence of digits (not starting with 0) whose value reflects the paren-number of the capture buffer to recurse to. \*(C`(?R)\*(C'\fR recurses to the beginning of the whole pattern. \*(C`(?0)\*(C'\fR is an alternate syntax for \*(C`(?R)\*(C'\fR. If \s-1PARNO\s0 is preceded by a plus or minus sign then it is assumed to be relative, with negative numbers indicating preceding capture buffers and positive ones following. Thus \*(C`(?\-1)\*(C'\fR refers to the most recently declared buffer, and \*(C`(?+1)\*(C'\fR indicates the next buffer to be declared. Note that the counting for relative recursion differs from that of relative backreferences, in that with recursion unclosed buffers are included. The following pattern matches a function foo() which may contain balanced parentheses as the argument. $re = qr{ ( # paren group 1 (full function)
foo
( # paren group 2 (parens)
\(
( # paren group 3 (contents of parens)
(?:
(?> [^()]+ ) # Non−parens without backtracking
|
(?2) # Recurse to start of paren group 2
)*
)
\)
)
)
}x;
If the pattern was used as follows 'foo(bar(baz)+baz(bop))'=~/$re/
and print "\$1 = $1\n",
"\$2 = $2\n",
"\$3 = $3\n";
the output produced should be the following: $1 = foo(bar(baz)+baz(bop))
$2 = (bar(baz)+baz(bop))
$3 = bar(baz)+baz(bop)
If there is no corresponding capture buffer defined, then it is a fatal error. Recursing deeper than 50 times without consuming any input string will also result in a fatal error. The maximum depth is compiled into perl, so changing it requires a custom build. The following shows how using negative indexing can make it easier to embed recursive patterns inside of a \*(C`qr//\*(C'\fR construct for later use: my $parens = qr/(\((?:[^()]++|(?−1))*+\))/;
if (/foo $parens \s+ + \s+ bar $parens/x) {
# do something here...
}
Note that this pattern does not behave the same way as the equivalent PCRE or Python construct of the same form. In Perl you can backtrack into a recursed group, in PCRE and Python the recursed into group is treated as atomic. Also, modifiers are resolved at compile time, so constructs like (?i:(?1)) or (?:(?i)(?1)) do not affect how the sub-pattern will be processed. (?&NAME) Recurse to a named subpattern. Identical to \*(C`(?PARNO)\*(C'\fR except that the parenthesis to recurse to is determined by name. If multiple parentheses have the same name, then it recurses to the leftmost. It is an error to refer to a name that is not declared somewhere in the pattern. NOTE: In order to make things easier for programmers with experience with the Python or PCRE regex engines the pattern \*(C`(?P>NAME)\*(C'\fR may be used instead of \*(C`(?&NAME)\*(C'\fR. (?(condition)yes−pattern|no−pattern) (?(condition)yes−pattern) Conditional expression. \*(C`(condition)\*(C'\fR should be either an integer in parentheses (which is valid if the corresponding pair of parentheses matched), a look−ahead/look−behind/evaluate zero-width assertion, a name in angle brackets or single quotes (which is valid if a buffer with the given name matched), or the special symbol (R) (true when evaluated inside of recursion or eval). Additionally the R may be followed by a number, (which will be true when evaluated when recursing inside of the appropriate group), or by &NAME, in which case it will be true only when evaluated during recursion in the named group. Here's a summary of the possible predicates: (1) (2) ... Checks if the numbered capturing buffer has matched something. (<NAME>) ('NAME') Checks if a buffer with the given name has matched something. (?{ CODE }) Treats the code block as the condition. (R) Checks if the expression has been evaluated inside of recursion. (R1) (R2) ... Checks if the expression has been evaluated while executing directly inside of the n−th capture group. This check is the regex equivalent of if ((caller(0))[3] eq 'subname') { ... }
In other words, it does not check the full recursion stack. (R&NAME) Similar to \*(C`(R1)\*(C'\fR, this predicate checks to see if we're executing directly inside of the leftmost group with a given name (this is the same logic used by \*(C`(?&NAME)\*(C'\fR to disambiguate). It does not check the full stack, but only the name of the innermost active recursion. (DEFINE) In this case, the yes-pattern is never directly executed, and no no-pattern is allowed. Similar in spirit to \*(C`(?{0})\*(C'\fR but more efficient. See below for details. For example: m{ ( \( )?
[^()]+
(?(1) \) )
}x
matches a chunk of non-parentheses, possibly included in parentheses themselves. A special form is the \*(C`(DEFINE)\*(C'\fR predicate, which never executes directly its yes-pattern, and does not allow a no-pattern. This allows to define subpatterns which will be executed only by using the recursion mechanism. This way, you can define a set of regular expression rules that can be bundled into any pattern you choose. It is recommended that for this usage you put the DEFINE block at the end of the pattern, and that you name any subpatterns defined within it. Also, it's worth noting that patterns defined this way probably will not be as efficient, as the optimiser is not very clever about handling them. An example of how this might be used is as follows: /(?<NAME>(?&NAME_PAT))(?<ADDR>(?&ADDRESS_PAT))
(?(DEFINE)
(?<NAME_PAT>....)
(?<ADRESS_PAT>....)
)/x
Note that capture buffers matched inside of recursion are not accessible after the recursion returns, so the extra layer of capturing buffers is necessary. Thus $+{NAME_PAT} would not be defined even though $+{NAME} would be. (?>pattern) An ‟independent” subexpression, one which matches the substring that a standalone \*(C`pattern\*(C'\fR would match if anchored at the given position, and it matches nothing other than this substring. This construct is useful for optimizations of what would otherwise be ‟eternal” matches, because it will not backtrack (see ‟Backtracking”). It may also be useful in places where the ‟grab all you can, and do not give anything back” semantic is desirable. For example: \*(C`^(?>a*)ab\*(C'\fR will never match, since \f(CW\*(C`(?>a*)\*(C'\fR (anchored at the beginning of string, as above) will match all characters \*(C`a\*(C'\fR at the beginning of string, leaving no \f(CW\*(C`a\*(C'\fR for \*(C`ab\*(C'\fR to match. In contrast, \f(CW\*(C`a*ab\*(C'\fR will match the same as \f(CW\*(C`a+b\*(C'\fR, since the match of the subgroup \*(C`a*\*(C'\fR is influenced by the following group \*(C`ab\*(C'\fR (see \*(L"Backtracking\*(R"). In particular, \f(CW\*(C`a*\*(C'\fR inside \*(C`a*ab\*(C'\fR will match fewer characters than a standalone \f(CW\*(C`a*\*(C'\fR, since this makes the tail match. An effect similar to \*(C`(?>pattern)\*(C'\fR may be achieved by writing \*(C`(?=(pattern))\e1\*(C'\fR. This matches the same substring as a standalone \*(C`a+\*(C'\fR, and the following \f(CW\*(C`\e1\*(C'\fR eats the matched string; it therefore makes a zero-length assertion into an analogue of \*(C`(?>...)\*(C'\fR. (The difference between these two constructs is that the second one uses a capturing group, thus shifting ordinals of backreferences in the rest of a regular expression.) Consider this pattern: m{ \(
(
[^()]+ # x+
|
\( [^()]* \)
)+
\)
}x
That will efficiently match a nonempty group with matching parentheses two levels deep or less. However, if there is no such group, it will take virtually forever on a long string. That's because there are so many different ways to split a long string into several substrings. This is what \*(C`(.+)+\*(C'\fR is doing, and \f(CW\*(C`(.+)+\*(C'\fR is similar to a subpattern of the above pattern. Consider how the pattern above detects no-match on \*(C`((()aaaaaaaaaaaaaaaaaa\*(C'\fR in several seconds, but that each extra letter doubles this time. This exponential performance will make it appear that your program has hung. However, a tiny change to this pattern m{ \(
(
(?> [^()]+ ) # change x+ above to (?> x+ )
|
\( [^()]* \)
)+
\)
}x
which uses \*(C`(?>...)\*(C'\fR matches exactly when the one above does (verifying this yourself would be a productive exercise), but finishes in a fourth the time when used on a similar string with 1000000 \*(C`a\*(C'\fRs. Be aware, however, that this pattern currently triggers a warning message under the \*(C`use warnings\*(C'\fR pragma or \fB\-w\fR switch saying it "matches null string many times in regex". On simple groups, such as the pattern \*(C`(?> [^()]+ )\*(C'\fR, a comparable effect may be achieved by negative look-ahead, as in \*(C`[^()]+ (?! [^()] )\*(C'\fR. This was only 4 times slower on a string with 1000000 \*(C`a\*(C'\fRs. The ‟grab all you can, and do not give anything back” semantic is desirable in many situations where on the first sight a simple \*(C`()*\*(C'\fR looks like the correct solution. Suppose we parse text with comments being delimited by \*(C`#\*(C'\fR followed by some optional (horizontal) whitespace. Contrary to its appearance, \*(C`#[ \et]*\*(C'\fR \fIis not\fR the correct subexpression to match the comment delimiter, because it may ‟give up” some whitespace if the remainder of the pattern can be made to match that way. The correct answer is either one of these: (?>#[ \t]*)
#[ \t]*(?![ \t])
For example, to grab non-empty comments into $1, one should use either one of these: / (?> \# [ \t]* ) ( .+ ) /x;
/ \# [ \t]* ( [^ \t] .* ) /x;
Which one you pick depends on which of these expressions better reflects the above specification of comments. In some literature this construct is called ‟atomic matching” or ‟possessive matching”. Possessive quantifiers are equivalent to putting the item they are applied to inside of one of these constructs. The following equivalences apply: Quantifier Form Bracketing Form
−−−−−−−−−−−−−−− −−−−−−−−−−−−−−−
PAT*+ (?>PAT*)
PAT++ (?>PAT+)
PAT?+ (?>PAT?)
PAT{min,max}+ (?>PAT{min,max})
Special Backtracking Control VerbsWARNING: These patterns are experimental and subject to change or removal in a future version of Perl. Their usage in production code should be noted to avoid problems during upgrades. These special patterns are generally of the form \*(C`(*VERB:ARG)\*(C'\fR. Unless otherwise stated the ARG argument is optional; in some cases, it is forbidden. Any pattern containing a special backtracking verb that allows an argument has the special behaviour that when executed it sets the current packages' $REGERROR and $REGMARK variables. When doing so the following rules apply: On failure, the $REGERROR variable will be set to the ARG value of the verb pattern, if the verb was involved in the failure of the match. If the ARG part of the pattern was omitted, then $REGERROR will be set to the name of the last \*(C`(*MARK:NAME)\*(C'\fR pattern executed, or to \s-1TRUE\s0 if there was none. Also, the $REGMARK variable will be set to FALSE. On a successful match, the $REGERROR variable will be set to FALSE, and the $REGMARK variable will be set to the name of the last \*(C`(*MARK:NAME)\*(C'\fR pattern executed. See the explanation for the \*(C`(*MARK:NAME)\*(C'\fR verb below for more details. NOTE: $REGERROR and $REGMARK are not magic variables like $1 and most other regex related variables. They are not local to a scope, nor readonly, but instead are volatile package variables similar to $AUTOLOAD. Use \*(C`local\*(C'\fR to localize changes to them to a specific scope if necessary. If a pattern does not contain a special backtracking verb that allows an argument, then $REGERROR and $REGMARK are not touched at all. Verbs that take an argument (*PRUNE) (*PRUNE:NAME) This zero-width pattern prunes the backtracking tree at the current point when backtracked into on failure. Consider the pattern \*(C`A (*PRUNE) B\*(C'\fR, where A and B are complex patterns. Until the \*(C`(*PRUNE)\*(C'\fR verb is reached, A may backtrack as necessary to match. Once it is reached, matching continues in B, which may also backtrack as necessary; however, should B not match, then no further backtracking will take place, and the pattern will fail outright at the current starting position. The following example counts all the possible matching strings in a pattern (without actually matching any of them). 'aaab' =~ /a+b?(?{print "$&\n"; $count++})(*FAIL)/;
print "Count=$count\n";
which produces: aaab
aaa
aa
a
aab
aa
a
ab
a
Count=9
If we add a \*(C`(*PRUNE)\*(C'\fR before the count like the following 'aaab' =~ /a+b?(*PRUNE)(?{print "$&\n"; $count++})(*FAIL)/;
print "Count=$count\n";
we prevent backtracking and find the count of the longest matching at each matching starting point like so: aaab
aab
ab
Count=3
Any number of \*(C`(*PRUNE)\*(C'\fR assertions may be used in a pattern. See also \*(C`(?>pattern)\*(C'\fR and possessive quantifiers for other ways to control backtracking. In some cases, the use of \*(C`(*PRUNE)\*(C'\fR can be replaced with a \*(C`(?>pattern)\*(C'\fR with no functional difference; however, \*(C`(*PRUNE)\*(C'\fR can be used to handle cases that cannot be expressed using a \*(C`(?>pattern)\*(C'\fR alone. (*SKIP) (*SKIP:NAME) This zero-width pattern is similar to \*(C`(*PRUNE)\*(C'\fR, except that on failure it also signifies that whatever text that was matched leading up to the \*(C`(*SKIP)\*(C'\fR pattern being executed cannot be part of \fIany\fR match of this pattern. This effectively means that the regex engine ‟skips” forward to this position on failure and tries to match again, (assuming that there is sufficient room to match). The name of the \*(C`(*SKIP:NAME)\*(C'\fR pattern has special significance. If a \*(C`(*MARK:NAME)\*(C'\fR was encountered while matching, then it is that position which is used as the ‟skip point”. If no \*(C`(*MARK)\*(C'\fR of that name was encountered, then the \*(C`(*SKIP)\*(C'\fR operator has no effect. When used without a name the ‟skip point” is where the match point was when executing the (*SKIP) pattern. Compare the following to the examples in \*(C`(*PRUNE)\*(C'\fR, note the string is twice as long: 'aaabaaab' =~ /a+b?(*SKIP)(?{print "$&\n"; $count++})(*FAIL)/;
print "Count=$count\n";
outputs aaab
aaab
Count=2
Once the 'aaab' at the start of the string has matched, and the \*(C`(*SKIP)\*(C'\fR executed, the next starting point will be where the cursor was when the \*(C`(*SKIP)\*(C'\fR was executed. (*MARK:NAME) (*:NAME) (*MARK:NAME) (*:NAME) This zero-width pattern can be used to mark the point reached in a string when a certain part of the pattern has been successfully matched. This mark may be given a name. A later \*(C`(*SKIP)\*(C'\fR pattern will then skip forward to that point if backtracked into on failure. Any number of \*(C`(*MARK)\*(C'\fR patterns are allowed, and the \s-1NAME\s0 portion is optional and may be duplicated. In addition to interacting with the \*(C`(*SKIP)\*(C'\fR pattern, \f(CW\*(C`(*MARK:NAME)\*(C'\fR can be used to ‟label” a pattern branch, so that after matching, the program can determine which branches of the pattern were involved in the match. When a match is successful, the $REGMARK variable will be set to the name of the most recently executed \*(C`(*MARK:NAME)\*(C'\fR that was involved in the match. This can be used to determine which branch of a pattern was matched without using a separate capture buffer for each branch, which in turn can result in a performance improvement, as perl cannot optimize \*(C`/(?:(x)|(y)|(z))/\*(C'\fR as efficiently as something like \*(C`/(?:x(*MARK:x)|y(*MARK:y)|z(*MARK:z))/\*(C'\fR. When a match has failed, and unless another verb has been involved in failing the match and has provided its own name to use, the $REGERROR variable will be set to the name of the most recently executed \*(C`(*MARK:NAME)\*(C'\fR. See \*(C`(*SKIP)\*(C'\fR for more details. As a shortcut \*(C`(*MARK:NAME)\*(C'\fR can be written \f(CW\*(C`(*:NAME)\*(C'\fR. (*THEN) (*THEN:NAME) This is similar to the ‟cut group” operator \*(C`::\*(C'\fR from Perl 6. Like \*(C`(*PRUNE)\*(C'\fR, this verb always matches, and when backtracked into on failure, it causes the regex engine to try the next alternation in the innermost enclosing group (capturing or otherwise). Its name comes from the observation that this operation combined with the alternation operator (\*(C`|\*(C'\fR) can be used to create what is essentially a pattern-based if/then/else block: ( COND (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ )
Note that if this operator is used and NOT inside of an alternation then it acts exactly like the \*(C`(*PRUNE)\*(C'\fR operator. / A (*PRUNE) B /
is the same as / A (*THEN) B /
but / ( A (*THEN) B | C (*THEN) D ) /
is not the same as / ( A (*PRUNE) B | C (*PRUNE) D ) /
as after matching the A but failing on the B the \*(C`(*THEN)\*(C'\fR verb will backtrack and try C; but the \*(C`(*PRUNE)\*(C'\fR verb will simply fail. (*COMMIT) This is the Perl 6 ‟commit pattern” \*(C`<commit>\*(C'\fR or \f(CW\*(C`:::\*(C'\fR. It's a zero-width pattern similar to \*(C`(*SKIP)\*(C'\fR, except that when backtracked into on failure it causes the match to fail outright. No further attempts to find a valid match by advancing the start pointer will occur again. For example, 'aaabaaab' =~ /a+b?(*COMMIT)(?{print "$&\n"; $count++})(*FAIL)/;
print "Count=$count\n";
outputs aaab
Count=1
In other words, once the \*(C`(*COMMIT)\*(C'\fR has been entered, and if the pattern does not match, the regex engine will not try any further matching on the rest of the string. Verbs without an argument (*FAIL) (*F) This pattern matches nothing and always fails. It can be used to force the engine to backtrack. It is equivalent to \*(C`(?!)\*(C'\fR, but easier to read. In fact, \*(C`(?!)\*(C'\fR gets optimised into \f(CW\*(C`(*FAIL)\*(C'\fR internally. It is probably useful only when combined with \*(C`(?{})\*(C'\fR or \f(CW\*(C`(??{})\*(C'\fR. (*ACCEPT) WARNING: This feature is highly experimental. It is not recommended for production code. This pattern matches nothing and causes the end of successful matching at the point at which the \*(C`(*ACCEPT)\*(C'\fR pattern was encountered, regardless of whether there is actually more to match in the string. When inside of a nested pattern, such as recursion, or in a subpattern dynamically generated via \*(C`(??{})\*(C'\fR, only the innermost pattern is ended immediately. If the \*(C`(*ACCEPT)\*(C'\fR is inside of capturing buffers then the buffers are marked as ended at the point at which the \*(C`(*ACCEPT)\*(C'\fR was encountered. For instance: 'AB' =~ /(A (A|B(*ACCEPT)|C) D)(E)/x;
will match, and $1 will be \*(C`AB\*(C'\fR and \f(CW$2\fR will be \f(CW\*(C`B\*(C'\fR, \f(CW$3\fR will not be set. If another branch in the inner parentheses were matched, such as in the string 'ACDE', then the \*(C`D\*(C'\fR and \f(CW\*(C`E\*(C'\fR would have to be matched as well.
BacktrackingNOTE: This section presents an abstract approximation of regular expression behavior. For a more rigorous (and complicated) view of the rules involved in selecting a match among possible alternatives, see ‟Combining RE Pieces”. A fundamental feature of regular expression matching involves the notion called backtracking, which is currently used (when needed) by all regular non-possessive expression quantifiers, namely \*(C`*\*(C'\fR, \f(CW\*(C`*?\*(C'\fR, \f(CW\*(C`+\*(C'\fR, \*(C`+?\*(C'\fR, \f(CW\*(C`{n,m}\*(C'\fR, and \f(CW\*(C`{n,m}?\*(C'\fR. Backtracking is often optimized internally, but the general principle outlined here is valid. For a regular expression to match, the entire regular expression must match, not just part of it. So if the beginning of a pattern containing a quantifier succeeds in a way that causes later parts in the pattern to fail, the matching engine backs up and recalculates the beginning part\*(--that's why it's called backtracking. Here is an example of backtracking: Let's say you want to find the word following ‟foo” in the string ‟Food is on the foo table.”: $_ = "Food is on the foo table.";
if ( /\b(foo)\s+(\w+)/i ) {
print "$2 follows $1.\n";
}
When the match runs, the first part of the regular expression (\*(C`\eb(foo)\*(C'\fR) finds a possible match right at the beginning of the string, and loads up $1 with ‟Foo”. However, as soon as the matching engine sees that there's no whitespace following the ‟Foo” that it had saved in $1, it realizes its mistake and starts over again one character after where it had the tentative match. This time it goes all the way until the next occurrence of ‟foo”. The complete regular expression matches this time, and you get the expected output of ‟table follows foo.” Sometimes minimal matching can help a lot. Imagine you'd like to match everything between ‟foo” and ‟bar”. Initially, you write something like this: $_ = "The food is under the bar in the barn.";
if ( /foo(.*)bar/ ) {
print "got <$1>\n";
}
Which perhaps unexpectedly yields: got <d is under the bar in the >
That's because \*(C`.*\*(C'\fR was greedy, so you get everything between the first ‟foo” and the last ‟bar”. Here it's more effective to use minimal matching to make sure you get the text between a ‟foo” and the first ‟bar” thereafter. if ( /foo(.*?)bar/ ) { print "got <$1>\n" }
got <d is under the >
Here's another example. Let's say you'd like to match a number at the end of a string, and you also want to keep the preceding part of the match. So you write this: $_ = "I have 2 numbers: 53147";
if ( /(.*)(\d*)/ ) { # Wrong!
print "Beginning is <$1>, number is <$2>.\n";
}
That won't work at all, because \*(C`.*\*(C'\fR was greedy and gobbled up the whole string. As \*(C`\ed*\*(C'\fR can match on an empty string the complete regular expression matched successfully. Beginning is <I have 2 numbers: 53147>, number is <>.
Here are some variants, most of which don't work: $_ = "I have 2 numbers: 53147";
@pats = qw{
(.*)(\d*)
(.*)(\d+)
(.*?)(\d*)
(.*?)(\d+)
(.*)(\d+)$
(.*?)(\d+)$
(.*)\b(\d+)$
(.*\D)(\d+)$
};
for $pat (@pats) {
printf "%−12s ", $pat;
if ( /$pat/ ) {
print "<$1> <$2>\n";
} else {
print "FAIL\n";
}
}
That will print out: (.*)(\d*) <I have 2 numbers: 53147> <>
(.*)(\d+) <I have 2 numbers: 5314> <7>
(.*?)(\d*) <> <>
(.*?)(\d+) <I have > <2>
(.*)(\d+)$ <I have 2 numbers: 5314> <7>
(.*?)(\d+)$ <I have 2 numbers: > <53147>
(.*)\b(\d+)$ <I have 2 numbers: > <53147>
(.*\D)(\d+)$ <I have 2 numbers: > <53147>
As you see, this can be a bit tricky. It's important to realize that a regular expression is merely a set of assertions that gives a definition of success. There may be 0, 1, or several different ways that the definition might succeed against a particular string. And if there are multiple ways it might succeed, you need to understand backtracking to know which variety of success you will achieve. When using look-ahead assertions and negations, this can all get even trickier. Imagine you'd like to find a sequence of non-digits not followed by ‟123”. You might try to write that as $_ = "ABC123";
if ( /^\D*(?!123)/ ) { # Wrong!
print "Yup, no 123 in $_\n";
}
But that isn't going to match; at least, not the way you're hoping. It claims that there is no 123 in the string. Here's a clearer picture of why that pattern matches, contrary to popular expectations: $x = 'ABC123';
$y = 'ABC445';
print "1: got $1\n" if $x =~ /^(ABC)(?!123)/;
print "2: got $1\n" if $y =~ /^(ABC)(?!123)/;
print "3: got $1\n" if $x =~ /^(\D*)(?!123)/;
print "4: got $1\n" if $y =~ /^(\D*)(?!123)/;
This prints 2: got ABC
3: got AB
4: got ABC
You might have expected test 3 to fail because it seems to a more general purpose version of test 1. The important difference between them is that test 3 contains a quantifier (\*(C`\eD*\*(C'\fR) and so can use backtracking, whereas test 1 will not. What's happening is that you've asked ‟Is it true that at the start of $x, following 0 or more non-digits, you have something that's not 123?” If the pattern matcher had let \*(C`\eD*\*(C'\fR expand to \*(L"\s-1ABC\s0\*(R", this would have caused the whole pattern to fail. The search engine will initially match \*(C`\eD*\*(C'\fR with \*(L"\s-1ABC\s0\*(R". Then it will try to match \*(C`(?!123\*(C'\fR with \*(L"123\*(R", which fails. But because a quantifier (\*(C`\eD*\*(C'\fR) has been used in the regular expression, the search engine can backtrack and retry the match differently in the hope of matching the complete regular expression. The pattern really, really wants to succeed, so it uses the standard pattern back-off-and-retry and lets \*(C`\eD*\*(C'\fR expand to just \*(L"\s-1AB\s0\*(R" this time. Now there's indeed something following ‟AB” that is not ‟123”. It's ‟C123”, which suffices. We can deal with this by using both an assertion and a negation. We'll say that the first part in $1 must be followed both by a digit and by something that's not ‟123”. Remember that the look-aheads are zero-width expressions\*(--they only look, but don't consume any of the string in their match. So rewriting this way produces what you'd expect; that is, case 5 will fail, but case 6 succeeds: print "5: got $1\n" if $x =~ /^(\D*)(?=\d)(?!123)/;
print "6: got $1\n" if $y =~ /^(\D*)(?=\d)(?!123)/;
6: got ABC
In other words, the two zero-width assertions next to each other work as though they're ANDed together, just as you'd use any built-in assertions: \*(C`/^$/\*(C'\fR matches only if you're at the beginning of the line AND the end of the line simultaneously. The deeper underlying truth is that juxtaposition in regular expressions always means AND, except when you write an explicit OR using the vertical bar. \*(C`/ab/\*(C'\fR means match \*(L"a\*(R" \s-1AND\s0 (then) match \*(L"b\*(R", although the attempted matches are made at different positions because ‟a” is not a zero-width assertion, but a one-width assertion. WARNING: Particularly complicated regular expressions can take exponential time to solve because of the immense number of possible ways they can use backtracking to try for a match. For example, without internal optimizations done by the regular expression engine, this will take a painfully long time to run: 'aaaaaaaaaaaa' =~ /((a{0,5}){0,5})*[c]/
And if you used \*(C`*\*(C'\fR's in the internal groups instead of limiting them to 0 through 5 matches, then it would take forever\*(--or until you ran out of stack space. Moreover, these internal optimizations are not always applicable. For example, if you put \*(C`{0,5}\*(C'\fR instead of \f(CW\*(C`*\*(C'\fR on the external group, no current optimization is applicable, and the match takes a long time to finish. A powerful tool for optimizing such beasts is what is known as an ‟independent group”, which does not backtrack (see \*(C`(?>pattern)\*(C'\fR). Note also that zero-length look−ahead/look−behind assertions will not backtrack to make the tail match, since they are in ‟logical” context: only whether they match is considered relevant. For an example where side-effects of look-ahead might have influenced the following match, see \*(C`(?>pattern)\*(C'\fR.
Version 8 Regular ExpressionsIn case you're not familiar with the ‟regular” Version 8 regex routines, here are the pattern-matching rules not described above. Any single character matches itself, unless it is a metacharacter with a special meaning described here or above. You can cause characters that normally function as metacharacters to be interpreted literally by prefixing them with a ‟\” (e.g., ‟\.” matches a ‟.”, not any character; ‟\\” matches a ‟\”). This escape mechanism is also required for the character used as the pattern delimiter. A series of characters matches that series of characters in the target string, so the pattern \*(C`blurfl\*(C'\fR would match \*(L"blurfl\*(R" in the target string. You can specify a character class, by enclosing a list of characters in \*(C`[]\*(C'\fR, which will match any character from the list. If the first character after the ‟[” is ‟^”, the class matches any character not in the list. Within a list, the ‟−” character specifies a range, so that \*(C`a\-z\*(C'\fR represents all characters between \*(L"a\*(R" and \*(L"z\*(R", inclusive. If you want either ‟−” or ‟]” itself to be a member of a class, put it at the start of the list (possibly after a ‟^”), or escape it with a backslash. ‟−” is also taken literally when it is at the end of the list, just before the closing ‟]”. (The following all specify the same class of three characters: \*(C`[\-az]\*(C'\fR, \*(C`[az\-]\*(C'\fR, and \f(CW\*(C`[a\e\-z]\*(C'\fR. All are different from \f(CW\*(C`[a\-z]\*(C'\fR, which specifies a class containing twenty-six characters, even on EBCDIC-based character sets.) Also, if you try to use the character classes \*(C`\ew\*(C'\fR, \f(CW\*(C`\eW\*(C'\fR, \f(CW\*(C`\es\*(C'\fR, \f(CW\*(C`\eS\*(C'\fR, \f(CW\*(C`\ed\*(C'\fR, or \f(CW\*(C`\eD\*(C'\fR as endpoints of a range, the ‟−” is understood literally. Note also that the whole range idea is rather unportable between character sets\*(--and even within character sets they may cause results you probably didn't expect. A sound principle is to use only ranges that begin from and end at either alphabetics of equal case ([a−e], [A−E]), or digits ([0−9]). Anything else is unsafe. If in doubt, spell out the character sets in full. Characters may be specified using a metacharacter syntax much like that used in C: ‟\n” matches a newline, ‟\t” a tab, ‟\r” a carriage return, ‟\f” a form feed, etc. More generally, \nnn, where nnn is a string of octal digits, matches the character whose coded character set value is nnn. Similarly, \xnn, where nn are hexadecimal digits, matches the character whose numeric value is nn. The expression \cx matches the character control−x. Finally, the ‟.” metacharacter matches any character except ‟\n” (unless you use \*(C`/s\*(C'\fR). You can specify a series of alternatives for a pattern using ‟|” to separate them, so that \*(C`fee|fie|foe\*(C'\fR will match any of \*(L"fee\*(R", \*(L"fie\*(R", or ‟foe” in the target string (as would \*(C`f(e|i|o)e\*(C'\fR). The first alternative includes everything from the last pattern delimiter (‟(”, ‟[”, or the beginning of the pattern) up to the first ‟|”, and the last alternative contains everything from the last ‟|” to the next pattern delimiter. That's why it's common practice to include alternatives in parentheses: to minimize confusion about where they start and end. Alternatives are tried from left to right, so the first alternative found for which the entire expression matches, is the one that is chosen. This means that alternatives are not necessarily greedy. For example: when matching \*(C`foo|foot\*(C'\fR against \*(L"barefoot\*(R", only the \*(L"foo\*(R" part will match, as that is the first alternative tried, and it successfully matches the target string. (This might not seem important, but it is important when you are capturing matched text using parentheses.) Also remember that ‟|” is interpreted as a literal within square brackets, so if you write \*(C`[fee|fie|foe]\*(C'\fR you're really only matching \f(CW\*(C`[feio|]\*(C'\fR. Within a pattern, you may designate subpatterns for later reference by enclosing them in parentheses, and you may refer back to the nth subpattern later in the pattern using the metacharacter \n. Subpatterns are numbered based on the left to right order of their opening parenthesis. A backreference matches whatever actually matched the subpattern in the string being examined, not the rules for that subpattern. Therefore, \*(C`(0|0x)\ed*\es\e1\ed*\*(C'\fR will match ‟0x1234 0x4321”, but not ‟0x1234 01234”, because subpattern 1 matched ‟0x”, even though the rule \*(C`0|0x\*(C'\fR could potentially match the leading 0 in the second number.
Warning on \1 Instead of $1Some people get too used to writing things like: $pattern =~ s/(\W)/\\\1/g;
This is grandfathered for the RHS of a substitute to avoid shocking the sed addicts, but it's a dirty habit to get into. That's because in PerlThink, the righthand side of an \*(C`s///\*(C'\fR is a double-quoted string. \f(CW\*(C`\e1\*(C'\fR in the usual double-quoted string means a control-A. The customary Unix meaning of \*(C`\e1\*(C'\fR is kludged in for \f(CW\*(C`s///\*(C'\fR. However, if you get into the habit of doing that, you get yourself into trouble if you then add an \*(C`/e\*(C'\fR modifier. s/(\d+)/ \1 + 1 /eg; # causes warning under −w
Or if you try to do s/(\d+)/\1000/;
You can't disambiguate that by saying \*(C`\e{1}000\*(C'\fR, whereas you can fix it with \*(C`${1}000\*(C'\fR. The operation of interpolation should not be confused with the operation of matching a backreference. Certainly they mean two different things on the left side of the \*(C`s///\*(C'\fR.
Repeated Patterns Matching a Zero-length SubstringWARNING: Difficult material (and prose) ahead. This section needs a rewrite. Regular expressions provide a terse and powerful programming language. As with most other power tools, power comes together with the ability to wreak havoc. A common abuse of this power stems from the ability to make infinite loops using regular expressions, with something as innocuous as: 'foo' =~ m{ ( o? )* }x;
The \*(C`o?\*(C'\fR matches at the beginning of \f(CW\*(Aqfoo\*(Aq\fR, and since the position in the string is not moved by the match, \*(C`o?\*(C'\fR would match again and again because of the \*(C`*\*(C'\fR quantifier. Another common way to create a similar cycle is with the looping modifier \*(C`//g\*(C'\fR: @matches = ( 'foo' =~ m{ o? }xg );
or print "match: <$&>\n" while 'foo' =~ m{ o? }xg;
or the loop implied by split(). However, long experience has shown that many programming tasks may be significantly simplified by using repeated subexpressions that may match zero-length substrings. Here's a simple example being: @chars = split //, $string; # // is not magic in split
($whitewashed = $string) =~ s/()/ /g; # parens avoid magic s// /
Thus Perl allows such constructs, by forcefully breaking the infinite loop. The rules for this are different for lower-level loops given by the greedy quantifiers \*(C`*+{}\*(C'\fR, and for higher-level ones like the \*(C`/g\*(C'\fR modifier or \fIsplit()\fR operator. The lower-level loops are interrupted (that is, the loop is broken) when Perl detects that a repeated expression matched a zero-length substring. Thus m{ (?: NON_ZERO_LENGTH | ZERO_LENGTH )* }x;
is made equivalent to m{ (?: NON_ZERO_LENGTH )*
|
(?: ZERO_LENGTH )?
}x;
The higher level-loops preserve an additional state between iterations: whether the last match was zero-length. To break the loop, the following match after a zero-length match is prohibited to have a length of zero. This prohibition interacts with backtracking (see ‟Backtracking”), and so the second best match is chosen if the best match is of zero length. For example: $_ = 'bar';
s/\w??/<$&>/g;
results in \*(C`<><b><><a><><r><>\*(C'\fR. At each position of the string the best match given by non-greedy \*(C`??\*(C'\fR is the zero-length match, and the \fIsecond best match is what is matched by \*(C`\ew\*(C'\fR. Thus zero-length matches alternate with one-character-long matches. Similarly, for repeated \*(C`m/()/g\*(C'\fR the second-best match is the match at the position one notch further in the string. The additional state of being matched with zero-length is associated with the matched string, and is reset by each assignment to pos(). Zero-length matches at the end of the previous match are ignored during \*(C`split\*(C'\fR.
Combining RE PiecesEach of the elementary pieces of regular expressions which were described before (such as \*(C`ab\*(C'\fR or \f(CW\*(C`\eZ\*(C'\fR) could match at most one substring at the given position of the input string. However, in a typical regular expression these elementary pieces are combined into more complicated patterns using combining operators \*(C`ST\*(C'\fR, \f(CW\*(C`S|T\*(C'\fR, \f(CW\*(C`S*\*(C'\fR etc (in these examples \*(C`S\*(C'\fR and \f(CW\*(C`T\*(C'\fR are regular subexpressions). Such combinations can include alternatives, leading to a problem of choice: if we match a regular expression \*(C`a|ab\*(C'\fR against \f(CW"abc"\fR, will it match substring "a" or "ab"? One way to describe which substring is actually matched is the concept of backtracking (see ‟Backtracking”). However, this description is too low-level and makes you think in terms of a particular implementation. Another description starts with notions of ‟better”/‟worse”. All the substrings which may be matched by the given regular expression can be sorted from the ‟best” match to the ‟worst” match, and it is the ‟best” match which is chosen. This substitutes the question of ‟what is chosen?” by the question of ‟which matches are better, and which are worse?”. Again, for elementary pieces there is no such question, since at most one match at a given position is possible. This section describes the notion of better/worse for combining operators. In the description below \*(C`S\*(C'\fR and \f(CW\*(C`T\*(C'\fR are regular subexpressions. ST Consider two possible matches, \*(C`AB\*(C'\fR and \f(CW\*(C`A\*(AqB\*(Aq\*(C'\fR, \f(CW\*(C`A\*(C'\fR and \f(CW\*(C`A\*(Aq\*(C'\fR are substrings which can be matched by \*(C`S\*(C'\fR, \f(CW\*(C`B\*(C'\fR and \f(CW\*(C`B\*(Aq\*(C'\fR are substrings which can be matched by \*(C`T\*(C'\fR. If \*(C`A\*(C'\fR is better match for \f(CW\*(C`S\*(C'\fR than \f(CW\*(C`A\*(Aq\*(C'\fR, \f(CW\*(C`AB\*(C'\fR is a better match than \*(C`A\*(AqB\*(Aq\*(C'\fR. If \*(C`A\*(C'\fR and \f(CW\*(C`A\*(Aq\*(C'\fR coincide: \f(CW\*(C`AB\*(C'\fR is a better match than \f(CW\*(C`AB\*(Aq\*(C'\fR if \*(C`B\*(C'\fR is better match for \f(CW\*(C`T\*(C'\fR than \f(CW\*(C`B\*(Aq\*(C'\fR. S|T When \*(C`S\*(C'\fR can match, it is a better match than when only \f(CW\*(C`T\*(C'\fR can match. Ordering of two matches for \*(C`S\*(C'\fR is the same as for \f(CW\*(C`S\*(C'\fR. Similar for two matches for \*(C`T\*(C'\fR. S{REPEAT_COUNT} Matches as \*(C`SSS...S\*(C'\fR (repeated as many times as necessary). S{min,max} Matches as \*(C`S{max}|S{max\-1}|...|S{min+1}|S{min}\*(C'\fR. S{min,max}? Matches as \*(C`S{min}|S{min+1}|...|S{max\-1}|S{max}\*(C'\fR. S?, S*, S+ Same as \*(C`S{0,1}\*(C'\fR, \f(CW\*(C`S{0,BIG_NUMBER}\*(C'\fR, \f(CW\*(C`S{1,BIG_NUMBER}\*(C'\fR respectively. S??, S*?, S+? Same as \*(C`S{0,1}?\*(C'\fR, \f(CW\*(C`S{0,BIG_NUMBER}?\*(C'\fR, \f(CW\*(C`S{1,BIG_NUMBER}?\*(C'\fR respectively. (?>S) Matches the best match for \*(C`S\*(C'\fR and only that. (?=S), (?<=S) Only the best match for \*(C`S\*(C'\fR is considered. (This is important only if \*(C`S\*(C'\fR has capturing parentheses, and backreferences are used somewhere else in the whole regular expression.) (?!S), (?<!S) For this grouping operator there is no need to describe the ordering, since only whether or not \*(C`S\*(C'\fR can match is important. (??{ EXPR }), (?PARNO) The ordering is the same as for the regular expression which is the result of EXPR, or the pattern contained by capture buffer PARNO. (?(condition)yes−pattern|no−pattern) Recall that which of \*(C`yes\-pattern\*(C'\fR or \f(CW\*(C`no\-pattern\*(C'\fR actually matches is already determined. The ordering of the matches is the same as for the chosen subexpression. The above recipes describe the ordering of matches at a given position. One more rule is needed to understand how a match is determined for the whole regular expression: a match at an earlier position is always better than a match at a later position.
Creating Custom RE EnginesOverloaded constants (see overload) provide a simple way to extend the functionality of the RE engine. Suppose that we want to enable a new RE escape-sequence \*(C`\eY|\*(C'\fR which matches at a boundary between whitespace characters and non-whitespace characters. Note that \*(C`(?=\eS)(?<!\eS)|(?!\eS)(?<=\eS)\*(C'\fR matches exactly at these positions, so we want to have each \*(C`\eY|\*(C'\fR in the place of the more complicated version. We can create a module \*(C`customre\*(C'\fR to do this: package customre;
use overload;
sub import {
shift;
die "No argument to customre::import allowed" if @_;
overload::constant 'qr' => \&convert;
}
sub invalid { die "/$_[0]/: invalid escape '\\$_[1]'"}
# We must also take care of not escaping the legitimate \\Y|
# sequence, hence the presence of '\\' in the conversion rules.
my %rules = ( '\\' => '\\\\',
'Y|' => qr/(?=\S)(?<!\S)|(?!\S)(?<=\S)/ );
sub convert {
my $re = shift;
$re =~ s{
\\ ( \\ | Y . )
}
{ $rules{$1} or invalid($re,$1) }sgex;
return $re;
}
Now \*(C`use customre\*(C'\fR enables the new escape in constant regular expressions, i.e., those without any runtime variable interpolations. As documented in overload, this conversion will work only over literal parts of regular expressions. For \*(C`\eY|$re\eY|\*(C'\fR the variable part of this regular expression needs to be converted explicitly (but only if the special meaning of \*(C`\eY|\*(C'\fR should be enabled inside \f(CW$re\fR): use customre;
$re = <>;
chomp $re;
$re = customre::convert $re;
/\Y|$re\Y|/;
PCRE/Python SupportAs of Perl 5.10.0, Perl supports several Python/PCRE specific extensions to the regex syntax. While Perl programmers are encouraged to use the Perl specific syntax, the following are also accepted: (?PE<lt>NAMEE<gt>pattern) Define a named capture buffer. Equivalent to \*(C`(?<NAME>pattern)\*(C'\fR. (?P=NAME) Backreference to a named capture buffer. Equivalent to \*(C`\eg{NAME}\*(C'\fR. (?P>NAME) Subroutine call to a named capture buffer. Equivalent to \*(C`(?&NAME)\*(C'\fR.
BUGSThis document varies from difficult to understand to completely and utterly opaque. The wandering prose riddled with jargon is hard to fathom in several places. This document needs a rewrite that separates the tutorial content from the reference content.
SEE ALSOperlrequick. perlretut. ‟Regexp Quote-Like Operators” in perlop. ‟Gory details of parsing quoted constructs” in perlop. perlfaq6. ‟pos” in perlfunc. perllocale. perlebcdic. Mastering Regular Expressions by Jeffrey Friedl, published by O'Reilly and Associates. 0
Johanes Gumabo
Data Size : 286,949 byte
man-perlre.1Build : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 3 / 181,991
Visitor ID : :
Visitor IP : 18.227.105.110 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (parse_manual_page_|249|perlre.1|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\|
) (htmlprn|149|perlre.1|36/37|.el══─{─══. ds -- — |.el══─{─══. ds -- \|\(em\|
) (parse_manual_page_|249|perlre.1|41|br══─}─══|'br══─}─══
) (htmlprn|149|perlre.1|41|'br══─}─══ |'br══─}─══
) (rof_nr_x|149|perlre.1|51/52|\nF|.ie \nF ══─{─══. de IX
) (rof_unit_scale_px|41|perlre.1|51/52|F|.ie \nF ══─{─══. de IX
) (rof_if|19|perlre.1|51/52|\nF|.ie \nF ══─{─══. de IX
) (htmlprn|149|perlre.1|51/52|.ie \nF ══─{─══. de IX|.ie \nF ══─{─══. de IX
) (rof_escape_sequence|91|perlre.1|53|\$1\t\\n%\t"\\$2" |. tm Index:\\$1\t\\n%\t"\\$2"
) (parse_manual_page_|249|perlre.1|57|══─}─══|.══─}─══
) (htmlprn|149|perlre.1|57|.══─}─══ |.══─}─══
) (rof_escape_sequence|91|perlre.1|145|\*(C`m//\*(C'\fR, \f(CW\*(C`s///\*(C'\fR, \f(CW\*(C`qr//\*(C'\fR and \f(CW\*(C`??\*(C'\fR in \*(L"Regexp Quote-Like |\&\f(CW\*(C`m//\*(C'\fR, \f(CW\*(C`s///\*(C'\fR, \f(CW\*(C`qr//\*(C'\fR and \f(CW\*(C`??\*(C'\fR in \*(L"Regexp Quote-Like
) (rof_escape_sequence|91|perlre.1|174|\*(C`use locale\*(C'\fR is in effect, the case map is taken from the current |If \f(CW\*(C`use locale\*(C'\fR is in effect, the case map is taken from the current
) (rof_escape_sequence|91|perlre.1|194|\*(C`/x\*(C'\fR modifier", even though the delimiter |These are usually written as "the \f(CW\*(C`/x\*(C'\fR modifier", even though the delimiter
) (rof_escape_sequence|91|perlre.1|197|\*(C`(?...)\*(C'\fR construct. See below. |the \f(CW\*(C`(?...)\*(C'\fR construct. See below.
) (rof_escape_sequence|91|perlre.1|199|\*(C`/x\*(C'\fR modifier itself needs a little more explanation. It tells |The \f(CW\*(C`/x\*(C'\fR modifier itself needs a little more explanation. It tells
) (rof_escape_sequence|91|perlre.1|202|\*(C`#\*(C'\fR |your regular expression into (slightly) more readable parts. The \f(CW\*(C`#\*(C'\fR
) (rof_escape_sequence|91|perlre.1|205|\*(C`#\*(C'\fR characters in the pattern (outside a character |whitespace or \f(CW\*(C`#\*(C'\fR characters in the pattern (outside a character
) (rof_escape_sequence|91|perlre.1|206|\*(C`/x\*(C'\fR), then you'll either have to |class, where they are unaffected by \f(CW\*(C`/x\*(C'\fR), then you'll either have to
) (rof_escape_sequence|91|perlre.1|207|\*(C`\eQ...\eE\*(C'\fR) or encode them using octal |escape them (using backslashes or \f(CW\*(C`\eQ...\eE\*(C'\fR) or encode them using octal
) (rof_escape_sequence|91|perlre.1|210|\*(--perl has |be careful not to include the pattern delimiter in the comment\*(--perl has
) (rof_escape_sequence|91|perlre.1|213|\*(C`\eQ...\eE\*(C'\fR stays unaffected by \f(CW\*(C`/x\*(C'\fR. |a \f(CW\*(C`\eQ...\eE\*(C'\fR stays unaffected by \f(CW\*(C`/x\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|254|\*(C`/s\*(C'\fR modifier, which in effect tells Perl to pretend |newline unless you use the \f(CW\*(C`/s\*(C'\fR modifier, which in effect tells Perl to pretend
) (rof_escape_sequence|91|perlre.1|255|\*(--even if it isn't. |the string is a single line\*(--even if it isn't.
) (rof_escape_sequence|91|perlre.1|275|\*(C`{0,}\*(C'\fR, the \*(L"+\*(R" |is not optional.) The \*(L"*\*(R" quantifier is equivalent to \f(CW\*(C`{0,}\*(C'\fR, the \*(L"+\*(R"
) (rof_escape_sequence|91|perlre.1|276|\*(C`{1,}\*(C'\fR, and the \*(L"?\*(R" quantifier to \f(CW\*(C`{0,1}\*(C'\fR. n and m are limited |quantifier to \f(CW\*(C`{1,}\*(C'\fR, and the \*(L"?\*(R" quantifier to \f(CW\*(C`{0,1}\*(C'\fR. n and m are limited
) (rof_escape_sequence|91|perlre.1|321|\*(C`a++\*(C'\fR will gobble up all the \f(CW\*(C`a\*(C'\fR's in the |will never match, as the \f(CW\*(C`a++\*(C'\fR will gobble up all the \f(CW\*(C`a\*(C'\fR's in the
) (rof_escape_sequence|91|perlre.1|332|\*(C`(?>...)\*(C'\fR for more details; |help. See the independent subexpression \f(CW\*(C`(?>...)\*(C'\fR for more details;
) (rof_nr_x|149|perlre.1|345|\n \r \f \e \a \l \u \L \U \E \Q \0 \c \N \x" |.IX Xref "\t \n \r \f \e \a \l \u \L \U \E \Q \0 \c \N \x"
) (rof_escape_sequence|91|perlre.1|367|\*(C`use locale\*(C'\fR is in effect, the case map used by \f(CW\*(C`\el\*(C'\fR, \f(CW\*(C`\eL\*(C'\fR, \f(CW\*(C`\eu\*(C'\fR |If \f(CW\*(C`use locale\*(C'\fR is in effect, the case map used by \f(CW\*(C`\el\*(C'\fR, \f(CW\*(C`\eL\*(C'\fR, \f(CW\*(C`\eu\*(C'\fR
) (rof_escape_sequence|91|perlre.1|368|\*(C`\eU\*(C'\fR is taken from the current locale. See perllocale. For |and \f(CW\*(C`\eU\*(C'\fR is taken from the current locale. See perllocale. For
) (rof_escape_sequence|91|perlre.1|369|\*(C`\eN{name}\*(C'\fR, see charnames. |documentation of \f(CW\*(C`\eN{name}\*(C'\fR, see charnames.
) (rof_escape_sequence|91|perlre.1|371|\*(C`$\*(C'\fR or \f(CW\*(C`@\*(C'\fR within a \f(CW\*(C`\eQ\*(C'\fR sequence. |You cannot include a literal \f(CW\*(C`$\*(C'\fR or \f(CW\*(C`@\*(C'\fR within a \f(CW\*(C`\eQ\*(C'\fR sequence.
) (rof_escape_sequence|91|perlre.1|372|\*(C`$\*(C'\fR or \f(CW\*(C`@\*(C'\fR interpolates the corresponding variable, |An unescaped \f(CW\*(C`$\*(C'\fR or \f(CW\*(C`@\*(C'\fR interpolates the corresponding variable,
) (rof_escape_sequence|91|perlre.1|373|\*(C`\e$\*(C'\fR to be matched. |while escaping will cause the literal string \f(CW\*(C`\e$\*(C'\fR to be matched.
) (rof_escape_sequence|91|perlre.1|374|\*(C`m/\eQuser\eE\e@\eQhost/\*(C'\fR. |You'll need to write something like \f(CW\*(C`m/\eQuser\eE\e@\eQhost/\*(C'\fR.
) (rof_w|5|perlre.1|380|\w \W \s \S \d \D \X \p \P \C \g \k \N \K \v \V \h \H word whitespace character class backreference" |.IX Xref "\w \W \s \S \d \D \X \p \P \C \g \k \N \K \v \V \h \H word whitespace character class backreference"
) (rof_escape_sequence|91|perlre.1|412|\*(C`\ew\*(C'\fR matches a single alphanumeric character (an alphabetic |A \f(CW\*(C`\ew\*(C'\fR matches a single alphanumeric character (an alphabetic
) (rof_escape_sequence|91|perlre.1|413|\*(C`_\*(C'\fR, not a whole word. Use \f(CW\*(C`\ew+\*(C'\fR |character, or a decimal digit) or \f(CW\*(C`_\*(C'\fR, not a whole word. Use \f(CW\*(C`\ew+\*(C'\fR
) (rof_escape_sequence|91|perlre.1|415|\*(C`use locale\*(C'\fR is in effect, the list |as matching an English word). If \f(CW\*(C`use locale\*(C'\fR is in effect, the list
) (rof_escape_sequence|91|perlre.1|416|\*(C`\ew\*(C'\fR is taken from the current |of alphabetic characters generated by \f(CW\*(C`\ew\*(C'\fR is taken from the current
) (rof_escape_sequence|91|perlre.1|417|\*(C`\ew\*(C'\fR, \f(CW\*(C`\eW\*(C'\fR, \f(CW\*(C`\es\*(C'\fR, \f(CW\*(C`\eS\*(C'\fR, |locale. See perllocale. You may use \f(CW\*(C`\ew\*(C'\fR, \f(CW\*(C`\eW\*(C'\fR, \f(CW\*(C`\es\*(C'\fR, \f(CW\*(C`\eS\*(C'\fR,
) (rof_escape_sequence|91|perlre.1|418|\*(C`\ed\*(C'\fR, and \f(CW\*(C`\eD\*(C'\fR within character classes, but they aren't usable |\&\f(CW\*(C`\ed\*(C'\fR, and \f(CW\*(C`\eD\*(C'\fR within character classes, but they aren't usable
) (rof_escape_sequence|91|perlre.1|420|\*(C`\es\*(C'\fR matches |the \*(L"\-\*(R" is understood literally. If Unicode is in effect, \f(CW\*(C`\es\*(C'\fR matches
) (rof_escape_sequence|91|perlre.1|422|\*(C`\epP\*(C'\fR, \f(CW\*(C`\ePP\*(C'\fR, \f(CW\*(C`\eX\*(C'\fR and the possibility of defining |details about \f(CW\*(C`\epP\*(C'\fR, \f(CW\*(C`\ePP\*(C'\fR, \f(CW\*(C`\eX\*(C'\fR and the possibility of defining
) (rof_escape_sequence|91|perlre.1|423|\*(C`\ep\*(C'\fR and \f(CW\*(C`\eP\*(C'\fR properties, and perluniintro about Unicode |your own \f(CW\*(C`\ep\*(C'\fR and \f(CW\*(C`\eP\*(C'\fR properties, and perluniintro about Unicode
) (rof_w|5|perlre.1|425|\w \W word" |.IX Xref "\w \W word"
) (rof_escape_sequence|91|perlre.1|427|\*(C`\eR\*(C'\fR will atomically match a linebreak, including the network line-ending |\&\f(CW\*(C`\eR\*(C'\fR will atomically match a linebreak, including the network line-ending
) (rof_escape_sequence|91|perlre.1|429|\R" |.IX Xref "\R"
) (rof_escape_sequence|91|perlre.1|435|\*(C`\eR\*(C'\fR has no special meaning inside of a character class; |\&\fBNote:\fR \f(CW\*(C`\eR\*(C'\fR has no special meaning inside of a character class;
) (rof_escape_sequence|91|perlre.1|436|\*(C`\ev\*(C'\fR instead (vertical whitespace). |use \f(CW\*(C`\ev\*(C'\fR instead (vertical whitespace).
) (rof_escape_sequence|91|perlre.1|437|\R" |.IX Xref "\R"
) (rof_escape_sequence|91|perlre.1|446|\*(C`[\*(C'\fR and \f(CW\*(C`]\*(C'\fR brackets are \fIliteral\fR; |is also available. Note that the \f(CW\*(C`[\*(C'\fR and \f(CW\*(C`]\*(C'\fR brackets are \fIliteral\fR;
) (rof_escape_sequence|91|perlre.1|479|\*(C`[ \et]\*(C'\fR, \*(L"all horizontal whitespace\*(R". |A \s-1GNU\s0 extension equivalent to \f(CW\*(C`[ \et]\*(C'\fR, \*(L"all horizontal whitespace\*(R".
) (rof_escape_sequence|91|perlre.1|482|\*(C`\es\*(C'\fR since the \f(CW\*(C`[[:space:]]\*(C'\fR includes |Not exactly equivalent to \f(CW\*(C`\es\*(C'\fR since the \f(CW\*(C`[[:space:]]\*(C'\fR includes
) (rof_escape_sequence|91|perlre.1|488|\*(C`[:upper:]\*(C'\fR to match all the uppercase characters. |For example use \f(CW\*(C`[:upper:]\*(C'\fR to match all the uppercase characters.
) (rof_escape_sequence|91|perlre.1|489|\*(C`[]\*(C'\fR are part of the \f(CW\*(C`[::]\*(C'\fR construct, not part of the |Note that the \f(CW\*(C`[]\*(C'\fR are part of the \f(CW\*(C`[::]\*(C'\fR construct, not part of the
) (rof_escape_sequence|91|perlre.1|500|\p \p{}" |.IX Xref "character class \p \p{}"
) (rof_escape_sequence|91|perlre.1|522|\*(C`[[:lower:]]\*(C'\fR and \f(CW\*(C`\ep{IsLower}\*(C'\fR are equivalent. |For example \f(CW\*(C`[[:lower:]]\*(C'\fR and \f(CW\*(C`\ep{IsLower}\*(C'\fR are equivalent.
) (rof_escape_sequence|91|perlre.1|524|\*(C`[[:xxxxx:]]\*(C'\fR and \f(CW\*(C`\ep{IsXxxxx}\*(C'\fR |However, the equivalence between \f(CW\*(C`[[:xxxxx:]]\*(C'\fR and \f(CW\*(C`\ep{IsXxxxx}\*(C'\fR
) (rof_escape_sequence|91|perlre.1|528|\*(C`utf8\*(C'\fR pragma is not used but the \f(CW\*(C`locale\*(C'\fR pragma is, the |If the \f(CW\*(C`utf8\*(C'\fR pragma is not used but the \f(CW\*(C`locale\*(C'\fR pragma is, the
) (rof_escape_sequence|91|perlre.1|532|\*(C`locale\*(C'\fR or \f(CW\*(C`encoding\*(C'\fR pragmas are not used and |But if the \f(CW\*(C`locale\*(C'\fR or \f(CW\*(C`encoding\*(C'\fR pragmas are not used and
) (rof_escape_sequence|91|perlre.1|533|\*(C`utf8\*(C'\fR, then \f(CW\*(C`[[:xxxxx:]]\*(C'\fR (and \f(CW\*(C`\ew\*(C'\fR, etc.) |the string is not \f(CW\*(C`utf8\*(C'\fR, then \f(CW\*(C`[[:xxxxx:]]\*(C'\fR (and \f(CW\*(C`\ew\*(C'\fR, etc.)
) (rof_escape_sequence|91|perlre.1|534|\*(C`\ep{IsXxxxx}\*(C'\fR will |will not match characters 0x80\-0xff; whereas \f(CW\*(C`\ep{IsXxxxx}\*(C'\fR will
) (rof_escape_sequence|91|perlre.1|535|\*(C`utf8\*(C'\fR and can match these characters |force the string to \f(CW\*(C`utf8\*(C'\fR and can match these characters
) (rof_escape_sequence|91|perlre.1|539|\*(C`\ep{IsPrint}\*(C'\fR matches characters 0x09\-0x0d but \f(CW\*(C`[[:print:]]\*(C'\fR does not. |\&\f(CW\*(C`\ep{IsPrint}\*(C'\fR matches characters 0x09\-0x0d but \f(CW\*(C`[[:print:]]\*(C'\fR does not.
) (rof_escape_sequence|91|perlre.1|542|\*(C`[[:punct::]]\*(C'\fR matches the following but \f(CW\*(C`\ep{IsPunct}\*(C'\fR does not, |\&\f(CW\*(C`[[:punct::]]\*(C'\fR matches the following but \f(CW\*(C`\ep{IsPunct}\*(C'\fR does not,
) (rof_escape_sequence|91|perlre.1|570|\*(C`DEL\*(C'\fR). |the \fIord()\fR value of 127 (\f(CW\*(C`DEL\*(C'\fR).
) (rof_escape_sequence|91|perlre.1|610|\b \B \A \Z \z \G" |.IX Xref "zero-width assertion assertion regex, zero-width assertion regexp, zero-width assertion regular expression, zero-width assertion \b \B \A \Z \z \G"
) (rof_escape_sequence|91|perlre.1|622|\*(C`\eb\*(C'\fR) is a spot between two characters |A word boundary (\f(CW\*(C`\eb\*(C'\fR) is a spot between two characters
) (rof_escape_sequence|91|perlre.1|623|\*(C`\ew\*(C'\fR on one side of it and a \f(CW\*(C`\eW\*(C'\fR on the other side |that has a \f(CW\*(C`\ew\*(C'\fR on one side of it and a \f(CW\*(C`\eW\*(C'\fR on the other side
) (rof_escape_sequence|91|perlre.1|625|\*(C`\eW\*(C'\fR. (Within |beginning and end of the string as matching a \f(CW\*(C`\eW\*(C'\fR. (Within
) (rof_escape_sequence|91|perlre.1|626|\*(C`\eb\*(C'\fR represents backspace rather than a word |character classes \f(CW\*(C`\eb\*(C'\fR represents backspace rather than a word
) (rof_escape_sequence|91|perlre.1|628|\*(C`\eA\*(C'\fR and \f(CW\*(C`\eZ\*(C'\fR are just like \*(L"^\*(R" and \*(L"$\*(R", except that they |The \f(CW\*(C`\eA\*(C'\fR and \f(CW\*(C`\eZ\*(C'\fR are just like \*(L"^\*(R" and \*(L"$\*(R", except that they
) (rof_escape_sequence|91|perlre.1|629|\*(C`/m\*(C'\fR modifier is used, while |won't match multiple times when the \f(CW\*(C`/m\*(C'\fR modifier is used, while
) (rof_escape_sequence|91|perlre.1|632|\*(C`\ez\*(C'\fR. |newline, use \f(CW\*(C`\ez\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|633|\b \A \Z \z m" |.IX Xref "\b \A \Z \z m"
) (rof_escape_sequence|91|perlre.1|635|\*(C`\eG\*(C'\fR assertion can be used to chain global matches (using |The \f(CW\*(C`\eG\*(C'\fR assertion can be used to chain global matches (using
) (rof_escape_sequence|91|perlre.1|636|\*(C`m//g\*(C'\fR), as described in \*(L"Regexp Quote-Like Operators\*(R" in perlop. |\&\f(CW\*(C`m//g\*(C'\fR), as described in \*(L"Regexp Quote-Like Operators\*(R" in perlop.
) (rof_escape_sequence|91|perlre.1|637|\*(C`lex\*(C'\fR\-like scanners, when you have |It is also useful when writing \f(CW\*(C`lex\*(C'\fR\-like scanners, when you have
) (rof_escape_sequence|91|perlre.1|640|\*(C`\eG\*(C'\fR will match can also be influenced by using \f(CW\*(C`pos()\*(C'\fR as |where \f(CW\*(C`\eG\*(C'\fR will match can also be influenced by using \f(CW\*(C`pos()\*(C'\fR as
) (rof_escape_sequence|91|perlre.1|642|\*(C`\eG\*(C'\fR is |matches is modified somewhat, in that contents to the left of \f(CW\*(C`\eG\*(C'\fR is
) (rof_escape_sequence|91|perlre.1|645|\G" |.IX Xref "\G"
) (rof_escape_sequence|91|perlre.1|659|\*(C`\eG\*(C'\fR improperly used can result in an infinite |It is worth noting that \f(CW\*(C`\eG\*(C'\fR improperly used can result in an infinite
) (rof_escape_sequence|91|perlre.1|660|\*(C`\eG\*(C'\fR in an alternation. |loop. Take care when using patterns that include \f(CW\*(C`\eG\*(C'\fR in an alternation.
) (rof_escape_sequence|91|perlre.1|665|\*(C`( ... )\*(C'\fR creates capture buffers. To refer |The bracketing construct \f(CW\*(C`( ... )\*(C'\fR creates capture buffers. To refer
) (rof_escape_sequence|91|perlre.1|688|\*(C`\eg{N}\*(C'\fR notation (starting with perl |backreferences, Perl provides the \f(CW\*(C`\eg{N}\*(C'\fR notation (starting with perl
) (rof_escape_sequence|91|perlre.1|691|\*(C`\eg{N}\*(C'\fR notation is |following it. When N is a positive integer the \f(CW\*(C`\eg{N}\*(C'\fR notation is
) (rof_escape_sequence|91|perlre.1|696|\g{1} \g{-1} \g{name} relative backreference named backreference" |.IX Xref "\g{1} \g{-1} \g{name} relative backreference named backreference"
) (rof_escape_sequence|91|perlre.1|698|\*(C`\eg{\-1}\*(C'\fR refers to the last buffer, \f(CW\*(C`\eg{\-2}\*(C'\fR refers to the |Thus \f(CW\*(C`\eg{\-1}\*(C'\fR refers to the last buffer, \f(CW\*(C`\eg{\-2}\*(C'\fR refers to the
) (rof_escape_sequence|91|perlre.1|712|\*(C`/(Y) ( (X) \e3 \e1 )/x\*(C'\fR. |and would match the same as \f(CW\*(C`/(Y) ( (X) \e3 \e1 )/x\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|715|\*(C`(?...)\*(C'\fR to declare and \f(CW\*(C`\ek\*(C'\fR |backreferences. The notation is \f(CW\*(C`(?...)\*(C'\fR to declare and \f(CW\*(C`\ek\*(C'\fR
) (rof_escape_sequence|91|perlre.1|717|\*(C`\eg{name}\*(C'\fR backreference syntax. |name; and you may use the bracketed \f(CW\*(C`\eg{name}\*(C'\fR backreference syntax.
) (rof_escape_sequence|91|perlre.1|719|\*(C`%+\*(C'\fR hash. |Outside the pattern, a named capture buffer is available via the \f(CW\*(C`%+\*(C'\fR hash.
) (rof_escape_sequence|91|perlre.1|721|\*(C`\ek\*(C'\fR refer to the leftmost defined group. (Thus it's possible |and \f(CW\*(C`\ek\*(C'\fR refer to the leftmost defined group. (Thus it's possible
) (rof_escape_sequence|91|perlre.1|722|\*(C`(??{})\*(C'\fR |to do things with named capture buffers that would otherwise require \f(CW\*(C`(??{})\*(C'\fR
) (rof_escape_sequence|91|perlre.1|750|\*(C`$\`\*(C'\fR returns |also, but now it returns the name of the program.) \f(CW\*(C`$\`\*(C'\fR returns
) (rof_escape_sequence|91|perlre.1|751|\*(C`$\*(Aq\*(C'\fR returns everything |everything before the matched string. \f(CW\*(C`$\*(Aq\*(C'\fR returns everything
) (rof_escape_sequence|91|perlre.1|759|\*(C`$\`\*(C'\fR, \f(CW\*(C`$\*(Aq\*(C'\fR, and \f(CW$^N\fR) are all dynamically scoped |set (\f(CW$+\fR, \f(CW$&\fR, \f(CW\*(C`$\`\*(C'\fR, \f(CW\*(C`$\*(Aq\*(C'\fR, and \f(CW$^N\fR) are all dynamically scoped
) (rof_escape_sequence|91|perlre.1|768|\*(C`$\`\*(C'\fR, or |\&\fB\s-1WARNING\s0\fR: Once Perl sees that you need one of \f(CW$&\fR, \f(CW\*(C`$\`\*(C'\fR, or
) (rof_escape_sequence|91|perlre.1|769|\*(C`$\*(Aq\*(C'\fR anywhere in the program, it has to provide them for every |\&\f(CW\*(C`$\*(Aq\*(C'\fR anywhere in the program, it has to provide them for every
) (rof_escape_sequence|91|perlre.1|774|\*(C`(?: ... )\*(C'\fR instead.) But if you never |extended regular expression \f(CW\*(C`(?: ... )\*(C'\fR instead.) But if you never
) (rof_escape_sequence|91|perlre.1|775|\*(C`$\`\*(C'\fR or \f(CW\*(C`$\*(Aq\*(C'\fR, then patterns \fIwithout\fR capturing |use \f(CW$&\fR, \f(CW\*(C`$\`\*(C'\fR or \f(CW\*(C`$\*(Aq\*(C'\fR, then patterns \fIwithout\fR capturing
) (rof_escape_sequence|91|perlre.1|776|\*(C`$\*(Aq\*(C'\fR, and \f(CW\*(C`$\`\*(C'\fR |parentheses will not be penalized. So avoid \f(CW$&\fR, \f(CW\*(C`$\*(Aq\*(C'\fR, and \f(CW\*(C`$\`\*(C'\fR
) (rof_escape_sequence|91|perlre.1|783|\*(C`${^PREMATCH}\*(C'\fR, |As a workaround for this problem, Perl 5.10.0 introduces \f(CW\*(C`${^PREMATCH}\*(C'\fR,
) (rof_escape_sequence|91|perlre.1|784|\*(C`${^MATCH}\*(C'\fR and \f(CW\*(C`${^POSTMATCH}\*(C'\fR, which are equivalent to \f(CW\*(C`$\`\*(C'\fR, \f(CW$&\fR |\&\f(CW\*(C`${^MATCH}\*(C'\fR and \f(CW\*(C`${^POSTMATCH}\*(C'\fR, which are equivalent to \f(CW\*(C`$\`\*(C'\fR, \f(CW$&\fR
) (rof_escape_sequence|91|perlre.1|785|\*(C`$\*(Aq\*(C'\fR, \fBexcept\fR that they are only guaranteed to be defined after a |and \f(CW\*(C`$\*(Aq\*(C'\fR, \fBexcept\fR that they are only guaranteed to be defined after a
) (rof_escape_sequence|91|perlre.1|786|\*(C`/p\*(C'\fR (preserve) modifier. |successful match that was executed with the \f(CW\*(C`/p\*(C'\fR (preserve) modifier.
) (rof_escape_sequence|91|perlre.1|792|\*(C`\eb\*(C'\fR, |Backslashed metacharacters in Perl are alphanumeric, such as \f(CW\*(C`\eb\*(C'\fR,
) (rof_escape_sequence|91|perlre.1|793|\*(C`\ew\*(C'\fR, \f(CW\*(C`\en\*(C'\fR. Unlike some other regular expression languages, there |\&\f(CW\*(C`\ew\*(C'\fR, \f(CW\*(C`\en\*(C'\fR. Unlike some other regular expression languages, there
) (rof_escape_sequence|91|perlre.1|805|\*(C`use locale\*(C'\fR is set, then this depends on the current locale.) |(If \f(CW\*(C`use locale\*(C'\fR is set, then this depends on the current locale.)
) (rof_escape_sequence|91|perlre.1|806|\*(C`\eQ\*(C'\fR |Today it is more common to use the \fIquotemeta()\fR function or the \f(CW\*(C`\eQ\*(C'\fR
) (rof_escape_sequence|91|perlre.1|815|\*(C`\eQ\*(C'\fR and \f(CW\*(C`\eE\*(C'\fR, double-quotish |interpolated variables) between \f(CW\*(C`\eQ\*(C'\fR and \f(CW\*(C`\eE\*(C'\fR, double-quotish
) (rof_escape_sequence|91|perlre.1|817|\*(C`\eQ...\eE\*(C'\fR, |\&\fIneed\fR to use literal backslashes within \f(CW\*(C`\eQ...\eE\*(C'\fR,
) (rof_escape_sequence|91|perlre.1|841|\*(C`/x\*(C'\fR modifier enables |A comment. The text is ignored. If the \f(CW\*(C`/x\*(C'\fR modifier enables
) (rof_escape_sequence|91|perlre.1|842|\*(C`#\*(C'\fR will suffice. Note that Perl closes |whitespace formatting, a simple \f(CW\*(C`#\*(C'\fR will suffice. Note that Perl closes
) (rof_escape_sequence|91|perlre.1|843|\*(C`)\*(C'\fR, so there is no way to put a literal |the comment as soon as it sees a \f(CW\*(C`)\*(C'\fR, so there is no way to put a literal
) (rof_escape_sequence|91|perlre.1|844|\*(C`)\*(C'\fR in the comment. |\&\f(CW\*(C`)\*(C'\fR in the comment.
) (rof_escape_sequence|91|perlre.1|850|\*(C`\-\*(C'\fR) for the remainder of the pattern or |turned off, if preceded by \f(CW\*(C`\-\*(C'\fR) for the remainder of the pattern or
) (rof_escape_sequence|91|perlre.1|856|\*(C`(?i)\*(C'\fR at the front of the pattern. For example: |include \f(CW\*(C`(?i)\*(C'\fR at the front of the pattern. For example:
) (rof_escape_sequence|91|perlre.1|874|\*(C`blah\*(C'\fR in any case, some spaces, and an exact (\fIincluding the case\fR!) |will match \f(CW\*(C`blah\*(C'\fR in any case, some spaces, and an exact (\fIincluding the case\fR!)
) (rof_escape_sequence|91|perlre.1|875|\*(C`/x\*(C'\fR modifier, and no \f(CW\*(C`/i\*(C'\fR |repetition of the previous word, assuming the \f(CW\*(C`/x\*(C'\fR modifier, and no \f(CW\*(C`/i\*(C'\fR
) (rof_escape_sequence|91|perlre.1|878|\*(C`p\*(C'\fR modifier is special in that it can only be enabled, |Note that the \f(CW\*(C`p\*(C'\fR modifier is special in that it can only be enabled,
) (rof_escape_sequence|91|perlre.1|880|\*(C`(?\-p)\*(C'\fR and \f(CW\*(C`(?\-p:...)\*(C'\fR are meaningless and will warn |effect. Thus \f(CW\*(C`(?\-p)\*(C'\fR and \f(CW\*(C`(?\-p:...)\*(C'\fR are meaningless and will warn
) (rof_escape_sequence|91|perlre.1|881|\*(C`use warnings\*(C'\fR. |when executed under \f(CW\*(C`use warnings\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|907|\*(C`?\*(C'\fR and \f(CW\*(C`:\*(C'\fR act as flags modifiers as with |Any letters between \f(CW\*(C`?\*(C'\fR and \f(CW\*(C`:\*(C'\fR act as flags modifiers as with
) (rof_escape_sequence|91|perlre.1|908|\*(C`(?imsx\-imsx)\*(C'\fR. For example, |\&\f(CW\*(C`(?imsx\-imsx)\*(C'\fR. For example,
) (rof_escape_sequence|91|perlre.1|948|\*(C`%+\*(C'\fR hash, that holds named captures. Consider using \f(CW\*(C`%\-\*(C'\fR instead. |the \f(CW\*(C`%+\*(C'\fR hash, that holds named captures. Consider using \f(CW\*(C`%\-\*(C'\fR instead.
) (rof_escape_sequence|91|perlre.1|962|\*(C`/\ew+(?=\et)/\*(C'\fR |A zero-width positive look-ahead assertion. For example, \f(CW\*(C`/\ew+(?=\et)/\*(C'\fR
) (rof_escape_sequence|91|perlre.1|968|\*(C`/foo(?!bar)/\*(C'\fR |A zero-width negative look-ahead assertion. For example \f(CW\*(C`/foo(?!bar)/\*(C'\fR
) (rof_escape_sequence|91|perlre.1|973|\*(C`/(?!foo)bar/\*(C'\fR |If you are looking for a \*(L"bar\*(R" that isn't preceded by a \*(L"foo\*(R", \f(CW\*(C`/(?!foo)bar/\*(C'\fR
) (rof_escape_sequence|91|perlre.1|974|\*(C`(?!foo)\*(C'\fR is just saying that |will not do what you want. That's because the \f(CW\*(C`(?!foo)\*(C'\fR is just saying that
) (rof_escape_sequence|91|perlre.1|976|\*(C`/(?!foo)...bar/\*(C'\fR for that. We |match. You would have to do something like \f(CW\*(C`/(?!foo)...bar/\*(C'\fR for that. We
) (rof_escape_sequence|91|perlre.1|978|\*(C`/(?:(?!foo)...|^.{0,2})bar/\*(C'\fR. |before it. You could cover that this way: \f(CW\*(C`/(?:(?!foo)...|^.{0,2})bar/\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|988|\K" |.IX Xref "(?<=) look-behind, positive lookbehind, positive \K"
) (rof_escape_sequence|91|perlre.1|990|\*(C`/(?<=\et)\ew+/\*(C'\fR |A zero-width positive look-behind assertion. For example, \f(CW\*(C`/(?<=\et)\ew+/\*(C'\fR
) (rof_escape_sequence|91|perlre.1|994|\*(C`\eK\*(C'\fR, which causes the |There is a special form of this construct, called \f(CW\*(C`\eK\*(C'\fR, which causes the
) (rof_escape_sequence|91|perlre.1|995|\*(C`\eK\*(C'\fR and |regex engine to \*(L"keep\*(R" everything it had matched prior to the \f(CW\*(C`\eK\*(C'\fR and
) (rof_escape_sequence|91|perlre.1|997|\*(C`\eK\*(C'\fR inside of another look-around assertion |look-behind. The use of \f(CW\*(C`\eK\*(C'\fR inside of another look-around assertion
) (rof_escape_sequence|91|perlre.1|1000|\*(C`\eK\*(C'\fR may be significantly more efficient than the |For various reasons \f(CW\*(C`\eK\*(C'\fR may be significantly more efficient than the
) (rof_escape_sequence|91|perlre.1|1001|\*(C`(?<=...)\*(C'\fR construct, and it is especially useful in |equivalent \f(CW\*(C`(?<=...)\*(C'\fR construct, and it is especially useful in
) (rof_escape_sequence|91|perlre.1|1018|\*(C`/(?|A zero-width negative look-behind assertion. For example \f(CW\*(C`/(?) (rof_escape_sequence|91|perlre.1|1034|\*(C`()\*(C'\fR but for the additional fact that \f(CW\*(C`%+\*(C'\fR or \f(CW\*(C`%\-\*(C'\fR may be |parentheses \f(CW\*(C`()\*(C'\fR but for the additional fact that \f(CW\*(C`%+\*(C'\fR or \f(CW\*(C`%\-\*(C'\fR may be
) (rof_escape_sequence|91|perlre.1|1035|\*(C`perlvar\*(C'\fR |used after a successful match to refer to a named buffer. See \f(CW\*(C`perlvar\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1036|\*(C`%+\*(C'\fR and \f(CW\*(C`%\-\*(C'\fR hashes. |for more details on the \f(CW\*(C`%+\*(C'\fR and \f(CW\*(C`%\-\*(C'\fR hashes.
) (rof_escape_sequence|91|perlre.1|1041|\*(C`(?\*(AqNAME\*(Aqpattern)\*(C'\fR and \f(CW\*(C`(?pattern)\*(C'\fR are equivalent. |The forms \f(CW\*(C`(?\*(AqNAME\*(Aqpattern)\*(C'\fR and \f(CW\*(C`(?pattern)\*(C'\fR are equivalent.
) (rof_escape_sequence|91|perlre.1|1056|\*(C`/^[_A\-Za\-z][_A\-Za\-z0\-9]*\ez/\*(C'\fR or |In other words, it must match \f(CW\*(C`/^[_A\-Za\-z][_A\-Za\-z0\-9]*\ez/\*(C'\fR or
) (rof_escape_sequence|91|perlre.1|1061|\*(C`(?PENAMEEpattern)\*(C'\fR |with the Python or \s-1PCRE\s0 regex engines, the pattern \f(CW\*(C`(?PENAMEEpattern)\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1062|\*(C`(?pattern)\*(C'\fR; however this form does not |may be used instead of \f(CW\*(C`(?pattern)\*(C'\fR; however this form does not
) (rof_escape_sequence|91|perlre.1|1077|\*(C`(?)\*(C'\fR |It is an error to refer to a name not defined by a \f(CW\*(C`(?)\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1083|\*(C`(?P=NAME)\*(C'\fR |with the Python or \s-1PCRE\s0 regex engines, the pattern \f(CW\*(C`(?P=NAME)\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1084|\*(C`\ek\*(C'\fR. |may be used instead of \f(CW\*(C`\ek\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1095|\*(C`code\*(C'\fR is not interpolated. Currently, |always succeeds, and its \f(CW\*(C`code\*(C'\fR is not interpolated. Currently,
) (rof_escape_sequence|91|perlre.1|1096|\*(C`code\*(C'\fR ends are somewhat convoluted. |the rules to determine where the \f(CW\*(C`code\*(C'\fR ends are somewhat convoluted.
) (rof_escape_sequence|91|perlre.1|1108|\*(C`(?{...})\*(C'\fR block, \f(CW$_\fR refers to the string the regular |Inside the \f(CW\*(C`(?{...})\*(C'\fR block, \f(CW$_\fR refers to the string the regular
) (rof_escape_sequence|91|perlre.1|1109|\*(C`pos()\*(C'\fR to know what is |expression is matching against. You can also use \f(CW\*(C`pos()\*(C'\fR to know what is
) (rof_escape_sequence|91|perlre.1|1112|\*(C`code\*(C'\fR is properly scoped in the following sense: If the assertion |The \f(CW\*(C`code\*(C'\fR is properly scoped in the following sense: If the assertion
) (rof_escape_sequence|91|perlre.1|1114|\*(C`local\*(C'\fRization are undone, so that |\&\f(CW\*(C`local\*(C'\fRization are undone, so that
) (rof_escape_sequence|91|perlre.1|1132|\*(C`$res = 4\*(C'\fR. Note that after the match, \f(CW$cnt\fR returns to the globally |will set \f(CW\*(C`$res = 4\*(C'\fR. Note that after the match, \f(CW$cnt\fR returns to the globally
) (rof_escape_sequence|91|perlre.1|1133|\*(C`local\*(C'\fR operators |introduced value, because the scopes that restrict \f(CW\*(C`local\*(C'\fR operators
) (rof_escape_sequence|91|perlre.1|1136|\*(C`(?(condition)yes\-pattern|no\-pattern)\*(C'\fR |This assertion may be used as a \f(CW\*(C`(?(condition)yes\-pattern|no\-pattern)\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1138|\*(C`code\*(C'\fR is put into the special variable \f(CW$^R\fR. This happens |\&\f(CW\*(C`code\*(C'\fR is put into the special variable \f(CW$^R\fR. This happens
) (rof_escape_sequence|91|perlre.1|1139|\*(C`(?{ code })\*(C'\fR assertions |immediately, so \f(CW$^R\fR can be used from other \f(CW\*(C`(?{ code })\*(C'\fR assertions
) (rof_escape_sequence|91|perlre.1|1155|\*(C`use re \*(Aqeval\*(Aq\*(C'\fR pragma has been used (see re), or the |perilous \f(CW\*(C`use re \*(Aqeval\*(Aq\*(C'\fR pragma has been used (see re), or the
) (rof_escape_sequence|91|perlre.1|1156|\*(C`qr//\*(C'\fR operator (see |variables contain results of \f(CW\*(C`qr//\*(C'\fR operator (see
) (rof_escape_sequence|91|perlre.1|1171|\*(C`use re \*(Aqeval\*(Aq\*(C'\fR, though, it is no longer secure, |you turn on the \f(CW\*(C`use re \*(Aqeval\*(Aq\*(C'\fR, though, it is no longer secure,
) (rof_escape_sequence|91|perlre.1|1177|\*(C`m//\*(C'\fR or \f(CW\*(C`s///\*(C'\fR), |code may not invoke the regex engine either directly with \f(CW\*(C`m//\*(C'\fR or \f(CW\*(C`s///\*(C'\fR),
) (rof_escape_sequence|91|perlre.1|1178|\*(C`split\*(C'\fR. |or indirectly with functions such as \f(CW\*(C`split\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1188|\*(C`code\*(C'\fR is evaluated |This is a \*(L"postponed\*(R" regular subexpression. The \f(CW\*(C`code\*(C'\fR is evaluated
) (rof_escape_sequence|91|perlre.1|1203|\*(C`code\*(C'\fR is not interpolated. As before, the rules to determine |The \f(CW\*(C`code\*(C'\fR is not interpolated. As before, the rules to determine
) (rof_escape_sequence|91|perlre.1|1204|\*(C`code\*(C'\fR ends are currently somewhat convoluted. |where the \f(CW\*(C`code\*(C'\fR ends are currently somewhat convoluted.
) (rof_escape_sequence|91|perlre.1|1220|\*(C`(?PARNO)\*(C'\fR for a different, more efficient way to accomplish |See also \f(CW\*(C`(?PARNO)\*(C'\fR for a different, more efficient way to accomplish
) (rof_escape_sequence|91|perlre.1|1224|\*(C`m//\*(C'\fR or \f(CW\*(C`s///\*(C'\fR), |code may not invoke the regex engine either directly with \f(CW\*(C`m//\*(C'\fR or \f(CW\*(C`s///\*(C'\fR),
) (rof_escape_sequence|91|perlre.1|1225|\*(C`split\*(C'\fR. |or indirectly with functions such as \f(CW\*(C`split\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1234|\*(C`(??{ code })\*(C'\fR except it does not involve compiling any code, |Similar to \f(CW\*(C`(??{ code })\*(C'\fR except it does not involve compiling any code,
) (rof_escape_sequence|91|perlre.1|1241|\*(C`(?R)\*(C'\fR recurses to |the paren-number of the capture buffer to recurse to. \f(CW\*(C`(?R)\*(C'\fR recurses to
) (rof_escape_sequence|91|perlre.1|1242|\*(C`(?0)\*(C'\fR is an alternate syntax for |the beginning of the whole pattern. \f(CW\*(C`(?0)\*(C'\fR is an alternate syntax for
) (rof_escape_sequence|91|perlre.1|1243|\*(C`(?R)\*(C'\fR. If \s-1PARNO\s0 is preceded by a plus or minus sign then it is assumed |\&\f(CW\*(C`(?R)\*(C'\fR. If \s-1PARNO\s0 is preceded by a plus or minus sign then it is assumed
) (rof_escape_sequence|91|perlre.1|1245|\*(C`(?\-1)\*(C'\fR refers to the most recently |and positive ones following. Thus \f(CW\*(C`(?\-1)\*(C'\fR refers to the most recently
) (rof_escape_sequence|91|perlre.1|1246|\*(C`(?+1)\*(C'\fR indicates the next buffer to be declared. |declared buffer, and \f(CW\*(C`(?+1)\*(C'\fR indicates the next buffer to be declared.
) (rof_escape_sequence|91|perlre.1|1295|\*(C`qr//\*(C'\fR construct |easier to embed recursive patterns inside of a \f(CW\*(C`qr//\*(C'\fR construct
) (rof_escape_sequence|91|perlre.1|1315|\*(C`(?PARNO)\*(C'\fR except that the |Recurse to a named subpattern. Identical to \f(CW\*(C`(?PARNO)\*(C'\fR except that the
) (rof_escape_sequence|91|perlre.1|1323|\*(C`(?P>NAME)\*(C'\fR |with the Python or \s-1PCRE\s0 regex engines the pattern \f(CW\*(C`(?P>NAME)\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1324|\*(C`(?&NAME)\*(C'\fR. |may be used instead of \f(CW\*(C`(?&NAME)\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1334|\*(C`(condition)\*(C'\fR should be either an integer in |Conditional expression. \f(CW\*(C`(condition)\*(C'\fR should be either an integer in
) (rof_escape_sequence|91|perlre.1|1370|\*(C`(R1)\*(C'\fR, this predicate checks to see if we're executing |Similar to \f(CW\*(C`(R1)\*(C'\fR, this predicate checks to see if we're executing
) (rof_escape_sequence|91|perlre.1|1372|\*(C`(?&NAME)\*(C'\fR to disambiguate). It does not check the full |logic used by \f(CW\*(C`(?&NAME)\*(C'\fR to disambiguate). It does not check the full
) (rof_escape_sequence|91|perlre.1|1377|\*(C`(?{0})\*(C'\fR but more efficient. |no-pattern is allowed. Similar in spirit to \f(CW\*(C`(?{0})\*(C'\fR but more efficient.
) (rof_escape_sequence|91|perlre.1|1394|\*(C`(DEFINE)\*(C'\fR predicate, which never executes directly |A special form is the \f(CW\*(C`(DEFINE)\*(C'\fR predicate, which never executes directly
) (rof_escape_sequence|91|perlre.1|1427|\*(C`pattern\*(C'\fR would match if anchored at the given |that a \fIstandalone\fR \f(CW\*(C`pattern\*(C'\fR would match if anchored at the given
) (rof_escape_sequence|91|perlre.1|1434|\*(C`^(?>a*)ab\*(C'\fR will never match, since \f(CW\*(C`(?>a*)\*(C'\fR |For example: \f(CW\*(C`^(?>a*)ab\*(C'\fR will never match, since \f(CW\*(C`(?>a*)\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1436|\*(C`a\*(C'\fR at the beginning of string, leaving no \f(CW\*(C`a\*(C'\fR for |characters \f(CW\*(C`a\*(C'\fR at the beginning of string, leaving no \f(CW\*(C`a\*(C'\fR for
) (rof_escape_sequence|91|perlre.1|1437|\*(C`ab\*(C'\fR to match. In contrast, \f(CW\*(C`a*ab\*(C'\fR will match the same as \f(CW\*(C`a+b\*(C'\fR, |\&\f(CW\*(C`ab\*(C'\fR to match. In contrast, \f(CW\*(C`a*ab\*(C'\fR will match the same as \f(CW\*(C`a+b\*(C'\fR,
) (rof_escape_sequence|91|perlre.1|1438|\*(C`a*\*(C'\fR is influenced by the following |since the match of the subgroup \f(CW\*(C`a*\*(C'\fR is influenced by the following
) (rof_escape_sequence|91|perlre.1|1439|\*(C`ab\*(C'\fR (see \*(L"Backtracking\*(R"). In particular, \f(CW\*(C`a*\*(C'\fR inside |group \f(CW\*(C`ab\*(C'\fR (see \*(L"Backtracking\*(R"). In particular, \f(CW\*(C`a*\*(C'\fR inside
) (rof_escape_sequence|91|perlre.1|1440|\*(C`a*ab\*(C'\fR will match fewer characters than a standalone \f(CW\*(C`a*\*(C'\fR, since |\&\f(CW\*(C`a*ab\*(C'\fR will match fewer characters than a standalone \f(CW\*(C`a*\*(C'\fR, since
) (rof_escape_sequence|91|perlre.1|1443|\*(C`(?>pattern)\*(C'\fR may be achieved by writing |An effect similar to \f(CW\*(C`(?>pattern)\*(C'\fR may be achieved by writing
) (rof_escape_sequence|91|perlre.1|1444|\*(C`(?=(pattern))\e1\*(C'\fR. This matches the same substring as a standalone |\&\f(CW\*(C`(?=(pattern))\e1\*(C'\fR. This matches the same substring as a standalone
) (rof_escape_sequence|91|perlre.1|1445|\*(C`a+\*(C'\fR, and the following \f(CW\*(C`\e1\*(C'\fR eats the matched string; it therefore |\&\f(CW\*(C`a+\*(C'\fR, and the following \f(CW\*(C`\e1\*(C'\fR eats the matched string; it therefore
) (rof_escape_sequence|91|perlre.1|1446|\*(C`(?>...)\*(C'\fR. |makes a zero-length assertion into an analogue of \f(CW\*(C`(?>...)\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1468|\*(C`(.+)+\*(C'\fR is doing, and \f(CW\*(C`(.+)+\*(C'\fR is similar |substrings. This is what \f(CW\*(C`(.+)+\*(C'\fR is doing, and \f(CW\*(C`(.+)+\*(C'\fR is similar
) (rof_escape_sequence|91|perlre.1|1470|\*(C`((()aaaaaaaaaaaaaaaaaa\*(C'\fR in several |above detects no-match on \f(CW\*(C`((()aaaaaaaaaaaaaaaaaa\*(C'\fR in several
) (rof_escape_sequence|91|perlre.1|1486|\*(C`(?>...)\*(C'\fR matches exactly when the one above does (verifying |which uses \f(CW\*(C`(?>...)\*(C'\fR matches exactly when the one above does (verifying
) (rof_escape_sequence|91|perlre.1|1488|\*(C`a\*(C'\fRs. Be aware, |the time when used on a similar string with 1000000 \f(CW\*(C`a\*(C'\fRs. Be aware,
) (rof_escape_sequence|91|perlre.1|1490|\*(C`use warnings\*(C'\fR pragma or \fB\-w\fR switch saying it |the \f(CW\*(C`use warnings\*(C'\fR pragma or \fB\-w\fR switch saying it
) (rof_escape_sequence|91|perlre.1|1493|\*(C`(?> [^()]+ )\*(C'\fR, a comparable |On simple groups, such as the pattern \f(CW\*(C`(?> [^()]+ )\*(C'\fR, a comparable
) (rof_escape_sequence|91|perlre.1|1494|\*(C`[^()]+ (?! [^()] )\*(C'\fR. |effect may be achieved by negative look-ahead, as in \f(CW\*(C`[^()]+ (?! [^()] )\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1495|\*(C`a\*(C'\fRs. |This was only 4 times slower on a string with 1000000 \f(CW\*(C`a\*(C'\fRs.
) (rof_escape_sequence|91|perlre.1|1498|\*(C`()*\*(C'\fR looks like |in many situations where on the first sight a simple \f(CW\*(C`()*\*(C'\fR looks like
) (rof_escape_sequence|91|perlre.1|1500|\*(C`#\*(C'\fR followed by some optional (horizontal) whitespace. Contrary to |by \f(CW\*(C`#\*(C'\fR followed by some optional (horizontal) whitespace. Contrary to
) (rof_escape_sequence|91|perlre.1|1501|\*(C`#[ \et]*\*(C'\fR \fIis not\fR the correct subexpression to match |its appearance, \f(CW\*(C`#[ \et]*\*(C'\fR \fIis not\fR the correct subexpression to match
) (rof_escape_sequence|91|perlre.1|1542|\*(C`(*VERB:ARG)\*(C'\fR. Unless |These special patterns are generally of the form \f(CW\*(C`(*VERB:ARG)\*(C'\fR. Unless
) (rof_escape_sequence|91|perlre.1|1554|\*(C`(*MARK:NAME)\*(C'\fR pattern executed, or to \s-1TRUE\s0 if there was |name of the last \f(CW\*(C`(*MARK:NAME)\*(C'\fR pattern executed, or to \s-1TRUE\s0 if there was
) (rof_escape_sequence|91|perlre.1|1559|\*(C`(*MARK:NAME)\*(C'\fR pattern executed. See the explanation for the |\&\f(CW\*(C`(*MARK:NAME)\*(C'\fR pattern executed. See the explanation for the
) (rof_escape_sequence|91|perlre.1|1560|\*(C`(*MARK:NAME)\*(C'\fR verb below for more details. |\&\f(CW\*(C`(*MARK:NAME)\*(C'\fR verb below for more details.
) (rof_escape_sequence|91|perlre.1|1565|\*(C`local\*(C'\fR to localize changes to them to a specific scope if necessary. |Use \f(CW\*(C`local\*(C'\fR to localize changes to them to a specific scope if necessary.
) (rof_escape_sequence|91|perlre.1|1579|\*(C`A (*PRUNE) B\*(C'\fR, |when backtracked into on failure. Consider the pattern \f(CW\*(C`A (*PRUNE) B\*(C'\fR,
) (rof_escape_sequence|91|perlre.1|1580|\*(C`(*PRUNE)\*(C'\fR verb is reached, |where A and B are complex patterns. Until the \f(CW\*(C`(*PRUNE)\*(C'\fR verb is reached,
) (rof_escape_sequence|91|perlre.1|1609|\*(C`(*PRUNE)\*(C'\fR before the count like the following |If we add a \f(CW\*(C`(*PRUNE)\*(C'\fR before the count like the following
) (rof_escape_sequence|91|perlre.1|1626|\*(C`(*PRUNE)\*(C'\fR assertions may be used in a pattern. |Any number of \f(CW\*(C`(*PRUNE)\*(C'\fR assertions may be used in a pattern.
) (rof_escape_sequence|91|perlre.1|1628|\*(C`(?>pattern)\*(C'\fR and possessive quantifiers for other ways to |See also \f(CW\*(C`(?>pattern)\*(C'\fR and possessive quantifiers for other ways to
) (rof_escape_sequence|91|perlre.1|1629|\*(C`(*PRUNE)\*(C'\fR can be |control backtracking. In some cases, the use of \f(CW\*(C`(*PRUNE)\*(C'\fR can be
) (rof_escape_sequence|91|perlre.1|1630|\*(C`(?>pattern)\*(C'\fR with no functional difference; however, |replaced with a \f(CW\*(C`(?>pattern)\*(C'\fR with no functional difference; however,
) (rof_escape_sequence|91|perlre.1|1631|\*(C`(*PRUNE)\*(C'\fR can be used to handle cases that cannot be expressed using a |\&\f(CW\*(C`(*PRUNE)\*(C'\fR can be used to handle cases that cannot be expressed using a
) (rof_escape_sequence|91|perlre.1|1632|\*(C`(?>pattern)\*(C'\fR alone. |\&\f(CW\*(C`(?>pattern)\*(C'\fR alone.
) (rof_escape_sequence|91|perlre.1|1637|\*(C`(*PRUNE)\*(C'\fR, except that on |This zero-width pattern is similar to \f(CW\*(C`(*PRUNE)\*(C'\fR, except that on
) (rof_escape_sequence|91|perlre.1|1639|\*(C`(*SKIP)\*(C'\fR pattern being executed cannot be part of \fIany\fR match |to the \f(CW\*(C`(*SKIP)\*(C'\fR pattern being executed cannot be part of \fIany\fR match
) (rof_escape_sequence|91|perlre.1|1644|\*(C`(*SKIP:NAME)\*(C'\fR pattern has special significance. If a |The name of the \f(CW\*(C`(*SKIP:NAME)\*(C'\fR pattern has special significance. If a
) (rof_escape_sequence|91|perlre.1|1645|\*(C`(*MARK:NAME)\*(C'\fR was encountered while matching, then it is that position |\&\f(CW\*(C`(*MARK:NAME)\*(C'\fR was encountered while matching, then it is that position
) (rof_escape_sequence|91|perlre.1|1646|\*(C`(*MARK)\*(C'\fR of that name was |which is used as the \*(L"skip point\*(R". If no \f(CW\*(C`(*MARK)\*(C'\fR of that name was
) (rof_escape_sequence|91|perlre.1|1647|\*(C`(*SKIP)\*(C'\fR operator has no effect. When used |encountered, then the \f(CW\*(C`(*SKIP)\*(C'\fR operator has no effect. When used
) (rof_escape_sequence|91|perlre.1|1651|\*(C`(*PRUNE)\*(C'\fR, note the string |Compare the following to the examples in \f(CW\*(C`(*PRUNE)\*(C'\fR, note the string
) (rof_escape_sequence|91|perlre.1|1667|\*(C`(*SKIP)\*(C'\fR |Once the 'aaab' at the start of the string has matched, and the \f(CW\*(C`(*SKIP)\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1669|\*(C`(*SKIP)\*(C'\fR was executed. |\&\f(CW\*(C`(*SKIP)\*(C'\fR was executed.
) (rof_escape_sequence|91|perlre.1|1676|\*(C`(*SKIP)\*(C'\fR pattern will then skip |mark may be given a name. A later \f(CW\*(C`(*SKIP)\*(C'\fR pattern will then skip
) (rof_escape_sequence|91|perlre.1|1678|\*(C`(*MARK)\*(C'\fR patterns are allowed, and the \s-1NAME\s0 portion is optional and may |\&\f(CW\*(C`(*MARK)\*(C'\fR patterns are allowed, and the \s-1NAME\s0 portion is optional and may
) (rof_escape_sequence|91|perlre.1|1681|\*(C`(*SKIP)\*(C'\fR pattern, \f(CW\*(C`(*MARK:NAME)\*(C'\fR |In addition to interacting with the \f(CW\*(C`(*SKIP)\*(C'\fR pattern, \f(CW\*(C`(*MARK:NAME)\*(C'\fR
) (rof_escape_sequence|91|perlre.1|1687|\*(C`(*MARK:NAME)\*(C'\fR that was involved |name of the most recently executed \f(CW\*(C`(*MARK:NAME)\*(C'\fR that was involved
) (rof_escape_sequence|91|perlre.1|1693|\*(C`/(?:(x)|(y)|(z))/\*(C'\fR as efficiently as something like |\&\f(CW\*(C`/(?:(x)|(y)|(z))/\*(C'\fR as efficiently as something like
) (rof_escape_sequence|91|perlre.1|1694|\*(C`/(?:x(*MARK:x)|y(*MARK:y)|z(*MARK:z))/\*(C'\fR. |\&\f(CW\*(C`/(?:x(*MARK:x)|y(*MARK:y)|z(*MARK:z))/\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1699|\*(C`(*MARK:NAME)\*(C'\fR. |\&\f(CW\*(C`(*MARK:NAME)\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1701|\*(C`(*SKIP)\*(C'\fR for more details. |See \f(CW\*(C`(*SKIP)\*(C'\fR for more details.
) (rof_escape_sequence|91|perlre.1|1703|\*(C`(*MARK:NAME)\*(C'\fR can be written \f(CW\*(C`(*:NAME)\*(C'\fR. |As a shortcut \f(CW\*(C`(*MARK:NAME)\*(C'\fR can be written \f(CW\*(C`(*:NAME)\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1707|\*(C`::\*(C'\fR from Perl 6. Like |This is similar to the \*(L"cut group\*(R" operator \f(CW\*(C`::\*(C'\fR from Perl 6. Like
) (rof_escape_sequence|91|perlre.1|1708|\*(C`(*PRUNE)\*(C'\fR, this verb always matches, and when backtracked into on |\&\f(CW\*(C`(*PRUNE)\*(C'\fR, this verb always matches, and when backtracked into on
) (rof_escape_sequence|91|perlre.1|1713|\*(C`|\*(C'\fR) can be used to create what is essentially a |alternation operator (\f(CW\*(C`|\*(C'\fR) can be used to create what is essentially a
) (rof_escape_sequence|91|perlre.1|1721|\*(C`(*PRUNE)\*(C'\fR operator. |it acts exactly like the \f(CW\*(C`(*PRUNE)\*(C'\fR operator.
) (rof_escape_sequence|91|perlre.1|1745|\*(C`(*THEN)\*(C'\fR verb will |as after matching the A but failing on the B the \f(CW\*(C`(*THEN)\*(C'\fR verb will
) (rof_escape_sequence|91|perlre.1|1746|\*(C`(*PRUNE)\*(C'\fR verb will simply fail. |backtrack and try C; but the \f(CW\*(C`(*PRUNE)\*(C'\fR verb will simply fail.
) (rof_escape_sequence|91|perlre.1|1751|\*(C`\*(C'\fR or \f(CW\*(C`:::\*(C'\fR. It's a |This is the Perl 6 \*(L"commit pattern\*(R" \f(CW\*(C`\*(C'\fR or \f(CW\*(C`:::\*(C'\fR. It's a
) (rof_escape_sequence|91|perlre.1|1752|\*(C`(*SKIP)\*(C'\fR, except that when backtracked |zero-width pattern similar to \f(CW\*(C`(*SKIP)\*(C'\fR, except that when backtracked
) (rof_escape_sequence|91|perlre.1|1769|\*(C`(*COMMIT)\*(C'\fR has been entered, and if the pattern |In other words, once the \f(CW\*(C`(*COMMIT)\*(C'\fR has been entered, and if the pattern
) (rof_escape_sequence|91|perlre.1|1785|\*(C`(?!)\*(C'\fR, but easier to read. In |engine to backtrack. It is equivalent to \f(CW\*(C`(?!)\*(C'\fR, but easier to read. In
) (rof_escape_sequence|91|perlre.1|1786|\*(C`(?!)\*(C'\fR gets optimised into \f(CW\*(C`(*FAIL)\*(C'\fR internally. |fact, \f(CW\*(C`(?!)\*(C'\fR gets optimised into \f(CW\*(C`(*FAIL)\*(C'\fR internally.
) (rof_escape_sequence|91|perlre.1|1788|\*(C`(?{})\*(C'\fR or \f(CW\*(C`(??{})\*(C'\fR. |It is probably useful only when combined with \f(CW\*(C`(?{})\*(C'\fR or \f(CW\*(C`(??{})\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|1797|\*(C`(*ACCEPT)\*(C'\fR pattern was encountered, regardless of |the point at which the \f(CW\*(C`(*ACCEPT)\*(C'\fR pattern was encountered, regardless of
) (rof_escape_sequence|91|perlre.1|1800|\*(C`(??{})\*(C'\fR, only the innermost pattern is ended immediately. |via \f(CW\*(C`(??{})\*(C'\fR, only the innermost pattern is ended immediately.
) (rof_escape_sequence|91|perlre.1|1802|\*(C`(*ACCEPT)\*(C'\fR is inside of capturing buffers then the buffers are |If the \f(CW\*(C`(*ACCEPT)\*(C'\fR is inside of capturing buffers then the buffers are
) (rof_escape_sequence|91|perlre.1|1803|\*(C`(*ACCEPT)\*(C'\fR was encountered. |marked as ended at the point at which the \f(CW\*(C`(*ACCEPT)\*(C'\fR was encountered.
) (rof_escape_sequence|91|perlre.1|1810|\*(C`AB\*(C'\fR and \f(CW$2\fR will be \f(CW\*(C`B\*(C'\fR, \f(CW$3\fR will not |will match, and \f(CW$1\fR will be \f(CW\*(C`AB\*(C'\fR and \f(CW$2\fR will be \f(CW\*(C`B\*(C'\fR, \f(CW$3\fR will not
) (rof_escape_sequence|91|perlre.1|1812|\*(C`D\*(C'\fR and \f(CW\*(C`E\*(C'\fR would have to be matched as well. |string '\s-1ACDE\s0', then the \f(CW\*(C`D\*(C'\fR and \f(CW\*(C`E\*(C'\fR would have to be matched as well.
) (rof_escape_sequence|91|perlre.1|1826|\*(C`*\*(C'\fR, \f(CW\*(C`*?\*(C'\fR, \f(CW\*(C`+\*(C'\fR, |by all regular non-possessive expression quantifiers, namely \f(CW\*(C`*\*(C'\fR, \f(CW\*(C`*?\*(C'\fR, \f(CW\*(C`+\*(C'\fR,
) (rof_escape_sequence|91|perlre.1|1827|\*(C`+?\*(C'\fR, \f(CW\*(C`{n,m}\*(C'\fR, and \f(CW\*(C`{n,m}?\*(C'\fR. Backtracking is often optimized |\&\f(CW\*(C`+?\*(C'\fR, \f(CW\*(C`{n,m}\*(C'\fR, and \f(CW\*(C`{n,m}?\*(C'\fR. Backtracking is often optimized
) (rof_escape_sequence|91|perlre.1|1834|\*(--that's why it's called backtracking. |part\*(--that's why it's called backtracking.
) (rof_escape_sequence|91|perlre.1|1846|\*(C`\eb(foo)\*(C'\fR) |When the match runs, the first part of the regular expression (\f(CW\*(C`\eb(foo)\*(C'\fR)
) (rof_escape_sequence|91|perlre.1|1872|\*(C`.*\*(C'\fR was greedy, so you get everything between the |That's because \f(CW\*(C`.*\*(C'\fR was greedy, so you get everything between the
) (rof_escape_sequence|91|perlre.1|1893|\*(C`.*\*(C'\fR was greedy and gobbled up the |That won't work at all, because \f(CW\*(C`.*\*(C'\fR was greedy and gobbled up the
) (rof_escape_sequence|91|perlre.1|1894|\*(C`\ed*\*(C'\fR can match on an empty string the complete |whole string. As \f(CW\*(C`\ed*\*(C'\fR can match on an empty string the complete
) (rof_escape_sequence|91|perlre.1|1982|\*(C`\eD*\*(C'\fR) and so can use |them is that test 3 contains a quantifier (\f(CW\*(C`\eD*\*(C'\fR) and so can use
) (rof_escape_sequence|91|perlre.1|1986|\*(C`\eD*\*(C'\fR expand to \*(L"\s-1ABC\s0\*(R", this would have caused the whole pattern to |let \f(CW\*(C`\eD*\*(C'\fR expand to \*(L"\s-1ABC\s0\*(R", this would have caused the whole pattern to
) (rof_escape_sequence|91|perlre.1|1989|\*(C`\eD*\*(C'\fR with \*(L"\s-1ABC\s0\*(R". Then it will |The search engine will initially match \f(CW\*(C`\eD*\*(C'\fR with \*(L"\s-1ABC\s0\*(R". Then it will
) (rof_escape_sequence|91|perlre.1|1990|\*(C`(?!123\*(C'\fR with \*(L"123\*(R", which fails. But because |try to match \f(CW\*(C`(?!123\*(C'\fR with \*(L"123\*(R", which fails. But because
) (rof_escape_sequence|91|perlre.1|1991|\*(C`\eD*\*(C'\fR) has been used in the regular expression, the |a quantifier (\f(CW\*(C`\eD*\*(C'\fR) has been used in the regular expression, the
) (rof_escape_sequence|91|perlre.1|1996|\*(C`\eD*\*(C'\fR expand to just \*(L"\s-1AB\s0\*(R" this |standard pattern back-off-and-retry and lets \f(CW\*(C`\eD*\*(C'\fR expand to just \*(L"\s-1AB\s0\*(R" this
) (rof_escape_sequence|91|perlre.1|2003|\*(--they only look, but don't consume any |are zero-width expressions\*(--they only look, but don't consume any
) (rof_escape_sequence|91|perlre.1|2015|\*(C`/^$/\*(C'\fR |they're ANDed together, just as you'd use any built-in assertions: \f(CW\*(C`/^$/\*(C'\fR
) (rof_escape_sequence|91|perlre.1|2019|\*(C`/ab/\*(C'\fR means match \*(L"a\*(R" \s-1AND\s0 (then) match \*(L"b\*(R", |using the vertical bar. \f(CW\*(C`/ab/\*(C'\fR means match \*(L"a\*(R" \s-1AND\s0 (then) match \*(L"b\*(R",
) (rof_escape_sequence|91|perlre.1|2033|\*(C`*\*(C'\fR's in the internal groups instead of limiting them |And if you used \f(CW\*(C`*\*(C'\fR's in the internal groups instead of limiting them
) (rof_escape_sequence|91|perlre.1|2034|\*(--or until you ran |to 0 through 5 matches, then it would take forever\*(--or until you ran
) (rof_escape_sequence|91|perlre.1|2036|\*(C`{0,5}\*(C'\fR instead of \f(CW\*(C`*\*(C'\fR |always applicable. For example, if you put \f(CW\*(C`{0,5}\*(C'\fR instead of \f(CW\*(C`*\*(C'\fR
) (rof_escape_sequence|91|perlre.1|2042|\*(C`(?>pattern)\*(C'\fR). Note also that |which does not backtrack (see \f(CW\*(C`(?>pattern)\*(C'\fR). Note also that
) (rof_escape_sequence|91|perlre.1|2047|\*(C`(?>pattern)\*(C'\fR. |following match, see \f(CW\*(C`(?>pattern)\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2062|\*(C`blurfl\*(C'\fR would match \*(L"blurfl\*(R" in the target |string, so the pattern \f(CW\*(C`blurfl\*(C'\fR would match \*(L"blurfl\*(R" in the target
) (rof_escape_sequence|91|perlre.1|2066|\*(C`[]\*(C'\fR, which will match any character from the list. If the |in \f(CW\*(C`[]\*(C'\fR, which will match any character from the list. If the
) (rof_escape_sequence|91|perlre.1|2069|\*(C`a\-z\*(C'\fR represents all characters between \*(L"a\*(R" and \*(L"z\*(R", |range, so that \f(CW\*(C`a\-z\*(C'\fR represents all characters between \*(L"a\*(R" and \*(L"z\*(R",
) (rof_escape_sequence|91|perlre.1|2074|\*(C`[\-az]\*(C'\fR, |following all specify the same class of three characters: \f(CW\*(C`[\-az]\*(C'\fR,
) (rof_escape_sequence|91|perlre.1|2075|\*(C`[az\-]\*(C'\fR, and \f(CW\*(C`[a\e\-z]\*(C'\fR. All are different from \f(CW\*(C`[a\-z]\*(C'\fR, which |\&\f(CW\*(C`[az\-]\*(C'\fR, and \f(CW\*(C`[a\e\-z]\*(C'\fR. All are different from \f(CW\*(C`[a\-z]\*(C'\fR, which
) (rof_escape_sequence|91|perlre.1|2078|\*(C`\ew\*(C'\fR, \f(CW\*(C`\eW\*(C'\fR, \f(CW\*(C`\es\*(C'\fR, \f(CW\*(C`\eS\*(C'\fR, \f(CW\*(C`\ed\*(C'\fR, or \f(CW\*(C`\eD\*(C'\fR as endpoints of |classes \f(CW\*(C`\ew\*(C'\fR, \f(CW\*(C`\eW\*(C'\fR, \f(CW\*(C`\es\*(C'\fR, \f(CW\*(C`\eS\*(C'\fR, \f(CW\*(C`\ed\*(C'\fR, or \f(CW\*(C`\eD\*(C'\fR as endpoints of
) (rof_escape_sequence|91|perlre.1|2082|\*(--and even within character sets they may cause results |character sets\*(--and even within character sets they may cause results
) (rof_escape_sequence|91|perlre.1|2095|\*(C`/s\*(C'\fR). |matches any character except \*(L"\en\*(R" (unless you use \f(CW\*(C`/s\*(C'\fR).
) (rof_escape_sequence|91|perlre.1|2098|\*(C`fee|fie|foe\*(C'\fR will match any of \*(L"fee\*(R", \*(L"fie\*(R", |separate them, so that \f(CW\*(C`fee|fie|foe\*(C'\fR will match any of \*(L"fee\*(R", \*(L"fie\*(R",
) (rof_escape_sequence|91|perlre.1|2099|\*(C`f(e|i|o)e\*(C'\fR). The |or \*(L"foe\*(R" in the target string (as would \f(CW\*(C`f(e|i|o)e\*(C'\fR). The
) (rof_escape_sequence|91|perlre.1|2110|\*(C`foo|foot\*(C'\fR against \*(L"barefoot\*(R", only the \*(L"foo\*(R" |example: when matching \f(CW\*(C`foo|foot\*(C'\fR against \*(L"barefoot\*(R", only the \*(L"foo\*(R"
) (rof_escape_sequence|91|perlre.1|2116|\*(C`[fee|fie|foe]\*(C'\fR you're really only matching \f(CW\*(C`[feio|]\*(C'\fR. |so if you write \f(CW\*(C`[fee|fie|foe]\*(C'\fR you're really only matching \f(CW\*(C`[feio|]\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2124|\*(C`(0|0x)\ed*\es\e1\ed*\*(C'\fR will |the rules for that subpattern. Therefore, \f(CW\*(C`(0|0x)\ed*\es\e1\ed*\*(C'\fR will
) (rof_escape_sequence|91|perlre.1|2126|\*(C`0|0x\*(C'\fR could potentially match |1 matched \*(L"0x\*(R", even though the rule \f(CW\*(C`0|0x\*(C'\fR could potentially match
) (rof_escape_sequence|91|perlre.1|2139|\*(C`s///\*(C'\fR is a double-quoted string. \f(CW\*(C`\e1\*(C'\fR in |PerlThink, the righthand side of an \f(CW\*(C`s///\*(C'\fR is a double-quoted string. \f(CW\*(C`\e1\*(C'\fR in
) (rof_escape_sequence|91|perlre.1|2141|\*(C`\e1\*(C'\fR is kludged in for \f(CW\*(C`s///\*(C'\fR. However, if you get into the habit |meaning of \f(CW\*(C`\e1\*(C'\fR is kludged in for \f(CW\*(C`s///\*(C'\fR. However, if you get into the habit
) (rof_escape_sequence|91|perlre.1|2142|\*(C`/e\*(C'\fR |of doing that, you get yourself into trouble if you then add an \f(CW\*(C`/e\*(C'\fR
) (rof_escape_sequence|91|perlre.1|2155|\*(C`\e{1}000\*(C'\fR, whereas you can fix it with |You can't disambiguate that by saying \f(CW\*(C`\e{1}000\*(C'\fR, whereas you can fix it with
) (rof_escape_sequence|91|perlre.1|2156|\*(C`${1}000\*(C'\fR. The operation of interpolation should not be confused |\&\f(CW\*(C`${1}000\*(C'\fR. The operation of interpolation should not be confused
) (rof_escape_sequence|91|perlre.1|2158|\*(C`s///\*(C'\fR. |different things on the \fIleft\fR side of the \f(CW\*(C`s///\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2174|\*(C`o?\*(C'\fR matches at the beginning of \f(CW\*(Aqfoo\*(Aq\fR, and since the position |The \f(CW\*(C`o?\*(C'\fR matches at the beginning of \f(CW\*(Aqfoo\*(Aq\fR, and since the position
) (rof_escape_sequence|91|perlre.1|2175|\*(C`o?\*(C'\fR would match again and again |in the string is not moved by the match, \f(CW\*(C`o?\*(C'\fR would match again and again
) (rof_escape_sequence|91|perlre.1|2176|\*(C`*\*(C'\fR quantifier. Another common way to create a similar cycle |because of the \f(CW\*(C`*\*(C'\fR quantifier. Another common way to create a similar cycle
) (rof_escape_sequence|91|perlre.1|2177|\*(C`//g\*(C'\fR: |is with the looping modifier \f(CW\*(C`//g\*(C'\fR:
) (rof_escape_sequence|91|perlre.1|2202|\*(C`*+{}\*(C'\fR, and for higher-level |loops given by the greedy quantifiers \f(CW\*(C`*+{}\*(C'\fR, and for higher-level
) (rof_escape_sequence|91|perlre.1|2203|\*(C`/g\*(C'\fR modifier or \fIsplit()\fR operator. |ones like the \f(CW\*(C`/g\*(C'\fR modifier or \fIsplit()\fR operator.
) (rof_escape_sequence|91|perlre.1|2236|\*(C`<><><><>\*(C'\fR. At each position of the string the best |results in \f(CW\*(C`<><><><>\*(C'\fR. At each position of the string the best
) (rof_escape_sequence|91|perlre.1|2237|\*(C`??\*(C'\fR is the zero-length match, and the \fIsecond |match given by non-greedy \f(CW\*(C`??\*(C'\fR is the zero-length match, and the \fIsecond
) (rof_escape_sequence|91|perlre.1|2238|\*(C`\ew\*(C'\fR. Thus zero-length matches |best\fR match is what is matched by \f(CW\*(C`\ew\*(C'\fR. Thus zero-length matches
) (rof_escape_sequence|91|perlre.1|2241|\*(C`m/()/g\*(C'\fR the second-best match is the match at the |Similarly, for repeated \f(CW\*(C`m/()/g\*(C'\fR the second-best match is the match at the
) (rof_escape_sequence|91|perlre.1|2247|\*(C`split\*(C'\fR. |during \f(CW\*(C`split\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2251|\*(C`ab\*(C'\fR or \f(CW\*(C`\eZ\*(C'\fR) could match at most one substring |before (such as \f(CW\*(C`ab\*(C'\fR or \f(CW\*(C`\eZ\*(C'\fR) could match at most one substring
) (rof_escape_sequence|91|perlre.1|2254|\*(C`ST\*(C'\fR, \f(CW\*(C`S|T\*(C'\fR, \f(CW\*(C`S*\*(C'\fR etc |patterns using combining operators \f(CW\*(C`ST\*(C'\fR, \f(CW\*(C`S|T\*(C'\fR, \f(CW\*(C`S*\*(C'\fR etc
) (rof_escape_sequence|91|perlre.1|2255|\*(C`S\*(C'\fR and \f(CW\*(C`T\*(C'\fR are regular subexpressions). |(in these examples \f(CW\*(C`S\*(C'\fR and \f(CW\*(C`T\*(C'\fR are regular subexpressions).
) (rof_escape_sequence|91|perlre.1|2258|\*(C`a|ab\*(C'\fR against \f(CW"abc"\fR, will it match |if we match a regular expression \f(CW\*(C`a|ab\*(C'\fR against \f(CW"abc"\fR, will it match
) (rof_escape_sequence|91|perlre.1|2273|\*(C`S\*(C'\fR and \f(CW\*(C`T\*(C'\fR are regular subexpressions. |below \f(CW\*(C`S\*(C'\fR and \f(CW\*(C`T\*(C'\fR are regular subexpressions.
) (rof_escape_sequence|91|perlre.1|2277|\*(C`AB\*(C'\fR and \f(CW\*(C`A\*(AqB\*(Aq\*(C'\fR, \f(CW\*(C`A\*(C'\fR and \f(CW\*(C`A\*(Aq\*(C'\fR are |Consider two possible matches, \f(CW\*(C`AB\*(C'\fR and \f(CW\*(C`A\*(AqB\*(Aq\*(C'\fR, \f(CW\*(C`A\*(C'\fR and \f(CW\*(C`A\*(Aq\*(C'\fR are
) (rof_escape_sequence|91|perlre.1|2278|\*(C`S\*(C'\fR, \f(CW\*(C`B\*(C'\fR and \f(CW\*(C`B\*(Aq\*(C'\fR are substrings |substrings which can be matched by \f(CW\*(C`S\*(C'\fR, \f(CW\*(C`B\*(C'\fR and \f(CW\*(C`B\*(Aq\*(C'\fR are substrings
) (rof_escape_sequence|91|perlre.1|2279|\*(C`T\*(C'\fR. |which can be matched by \f(CW\*(C`T\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2281|\*(C`A\*(C'\fR is better match for \f(CW\*(C`S\*(C'\fR than \f(CW\*(C`A\*(Aq\*(C'\fR, \f(CW\*(C`AB\*(C'\fR is a better |If \f(CW\*(C`A\*(C'\fR is better match for \f(CW\*(C`S\*(C'\fR than \f(CW\*(C`A\*(Aq\*(C'\fR, \f(CW\*(C`AB\*(C'\fR is a better
) (rof_escape_sequence|91|perlre.1|2282|\*(C`A\*(AqB\*(Aq\*(C'\fR. |match than \f(CW\*(C`A\*(AqB\*(Aq\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2284|\*(C`A\*(C'\fR and \f(CW\*(C`A\*(Aq\*(C'\fR coincide: \f(CW\*(C`AB\*(C'\fR is a better match than \f(CW\*(C`AB\*(Aq\*(C'\fR if |If \f(CW\*(C`A\*(C'\fR and \f(CW\*(C`A\*(Aq\*(C'\fR coincide: \f(CW\*(C`AB\*(C'\fR is a better match than \f(CW\*(C`AB\*(Aq\*(C'\fR if
) (rof_escape_sequence|91|perlre.1|2285|\*(C`B\*(C'\fR is better match for \f(CW\*(C`T\*(C'\fR than \f(CW\*(C`B\*(Aq\*(C'\fR. |\&\f(CW\*(C`B\*(C'\fR is better match for \f(CW\*(C`T\*(C'\fR than \f(CW\*(C`B\*(Aq\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2289|\*(C`S\*(C'\fR can match, it is a better match than when only \f(CW\*(C`T\*(C'\fR can match. |When \f(CW\*(C`S\*(C'\fR can match, it is a better match than when only \f(CW\*(C`T\*(C'\fR can match.
) (rof_escape_sequence|91|perlre.1|2291|\*(C`S\*(C'\fR is the same as for \f(CW\*(C`S\*(C'\fR. Similar for |Ordering of two matches for \f(CW\*(C`S\*(C'\fR is the same as for \f(CW\*(C`S\*(C'\fR. Similar for
) (rof_escape_sequence|91|perlre.1|2292|\*(C`T\*(C'\fR. |two matches for \f(CW\*(C`T\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2296|\*(C`SSS...S\*(C'\fR (repeated as many times as necessary). |Matches as \f(CW\*(C`SSS...S\*(C'\fR (repeated as many times as necessary).
) (rof_escape_sequence|91|perlre.1|2300|\*(C`S{max}|S{max\-1}|...|S{min+1}|S{min}\*(C'\fR. |Matches as \f(CW\*(C`S{max}|S{max\-1}|...|S{min+1}|S{min}\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2304|\*(C`S{min}|S{min+1}|...|S{max\-1}|S{max}\*(C'\fR. |Matches as \f(CW\*(C`S{min}|S{min+1}|...|S{max\-1}|S{max}\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2308|\*(C`S{0,1}\*(C'\fR, \f(CW\*(C`S{0,BIG_NUMBER}\*(C'\fR, \f(CW\*(C`S{1,BIG_NUMBER}\*(C'\fR respectively. |Same as \f(CW\*(C`S{0,1}\*(C'\fR, \f(CW\*(C`S{0,BIG_NUMBER}\*(C'\fR, \f(CW\*(C`S{1,BIG_NUMBER}\*(C'\fR respectively.
) (rof_escape_sequence|91|perlre.1|2312|\*(C`S{0,1}?\*(C'\fR, \f(CW\*(C`S{0,BIG_NUMBER}?\*(C'\fR, \f(CW\*(C`S{1,BIG_NUMBER}?\*(C'\fR respectively. |Same as \f(CW\*(C`S{0,1}?\*(C'\fR, \f(CW\*(C`S{0,BIG_NUMBER}?\*(C'\fR, \f(CW\*(C`S{1,BIG_NUMBER}?\*(C'\fR respectively.
) (rof_escape_sequence|91|perlre.1|2316|\*(C`S\*(C'\fR and only that. |Matches the best match for \f(CW\*(C`S\*(C'\fR and only that.
) (rof_escape_sequence|91|perlre.1|2320|\*(C`S\*(C'\fR is considered. (This is important only if |Only the best match for \f(CW\*(C`S\*(C'\fR is considered. (This is important only if
) (rof_escape_sequence|91|perlre.1|2321|\*(C`S\*(C'\fR has capturing parentheses, and backreferences are used somewhere |\&\f(CW\*(C`S\*(C'\fR has capturing parentheses, and backreferences are used somewhere
) (rof_escape_sequence|91|perlre.1|2327|\*(C`S\*(C'\fR can match is important. |only whether or not \f(CW\*(C`S\*(C'\fR can match is important.
) (rof_escape_sequence|91|perlre.1|2336|\*(C`yes\-pattern\*(C'\fR or \f(CW\*(C`no\-pattern\*(C'\fR actually matches is |Recall that which of \f(CW\*(C`yes\-pattern\*(C'\fR or \f(CW\*(C`no\-pattern\*(C'\fR actually matches is
) (rof_escape_sequence|91|perlre.1|2349|\*(C`\eY|\*(C'\fR which |Suppose that we want to enable a new \s-1RE\s0 escape-sequence \f(CW\*(C`\eY|\*(C'\fR which
) (rof_escape_sequence|91|perlre.1|2351|\*(C`(?=\eS)(?|characters. Note that \f(CW\*(C`(?=\eS)(?) (rof_escape_sequence|91|perlre.1|2352|\*(C`\eY|\*(C'\fR in the place of the |at these positions, so we want to have each \f(CW\*(C`\eY|\*(C'\fR in the place of the
) (rof_escape_sequence|91|perlre.1|2353|\*(C`customre\*(C'\fR to do |more complicated version. We can create a module \f(CW\*(C`customre\*(C'\fR to do
) (rof_escape_sequence|91|perlre.1|2382|\*(C`use customre\*(C'\fR enables the new escape in constant regular |Now \f(CW\*(C`use customre\*(C'\fR enables the new escape in constant regular
) (rof_escape_sequence|91|perlre.1|2385|\*(C`\eY|$re\eY|\*(C'\fR the variable |literal parts of regular expressions. For \f(CW\*(C`\eY|$re\eY|\*(C'\fR the variable
) (rof_escape_sequence|91|perlre.1|2387|\*(C`\eY|\*(C'\fR should be enabled inside \f(CW$re\fR): |(but only if the special meaning of \f(CW\*(C`\eY|\*(C'\fR should be enabled inside \f(CW$re\fR):
) (rof_escape_sequence|91|perlre.1|2404|\*(C`(?pattern)\*(C'\fR. |Define a named capture buffer. Equivalent to \f(CW\*(C`(?pattern)\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2408|\*(C`\eg{NAME}\*(C'\fR. |Backreference to a named capture buffer. Equivalent to \f(CW\*(C`\eg{NAME}\*(C'\fR.
) (rof_escape_sequence|91|perlre.1|2412|\*(C`(?&NAME)\*(C'\fR. |Subroutine call to a named capture buffer. Equivalent to \f(CW\*(C`(?&NAME)\*(C'\fR.
)