perl

 view release on metacpan or  search on metacpan

pod/perlre.pod  view on Meta::CPAN

 {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++> will gobble up all the C<"a">'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<L</(?E<gt>I<pattern>)>> for more details;
possessive quantifiers are just syntactic sugar for that construct. For
instance the above example could also be written as follows:

   /"(?>(?:(?>[^"\\]+)|\\.)*)"/

Note that the possessive quantifier modifier can not be combined
with the non-greedy modifier. This is because it would make no sense.
Consider the follow equivalency table:

    Illegal         Legal
    ------------    ------
    X??+            X{0}
    X+?+            X{1}
    X{min,max}?+    X{min}

=head3 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)
 \cK         control char          (example: VT)
 \x{}, \x00  character whose ordinal is the given hexadecimal number
 \N{name}    named Unicode character or character sequence
 \N{U+263D}  Unicode character     (example: FIRST QUARTER MOON)
 \o{}, \000  character whose ordinal is the given octal number
 \l          lowercase next char (think vi)
 \u          uppercase next char (think vi)
 \L          lowercase until \E (think vi)
 \U          uppercase until \E (think vi)
 \Q          quote (disable) pattern metacharacters until \E
 \E          end either case modification or quoted section, think vi

Details are in L<perlop/Quote and Quote-like Operators>.

=head3 Character Classes and other Special Escapes

In addition, Perl defines the following:
X<\g> X<\k> X<\K> X<backreference>

 Sequence   Note    Description
  [...]     [1]  Match a character according to the rules of the
                   bracketed character class defined by the "...".
                   Example: [a-z] matches "a" or "b" or "c" ... or "z"
  [[:...:]] [2]  Match a character according to the rules of the POSIX
                   character class "..." within the outer bracketed
                   character class.  Example: [[:upper:]] matches any
                   uppercase character.
  (?[...])  [8]  Extended bracketed character class
  \w        [3]  Match a "word" character (alphanumeric plus "_", plus
                   other connector punctuation chars plus Unicode
                   marks)
  \W        [3]  Match a non-"word" character
  \s        [3]  Match a whitespace character
  \S        [3]  Match a non-whitespace character
  \d        [3]  Match a decimal digit character
  \D        [3]  Match a non-digit character
  \pP       [3]  Match P, named property.  Use \p{Prop} for longer names
  \PP       [3]  Match non-P
  \X        [4]  Match Unicode "eXtended grapheme cluster"
  \1        [5]  Backreference to a specific capture group or buffer.
                   '1' may actually be any positive integer.
  \g1       [5]  Backreference to a specific or previous group,
  \g{-1}    [5]  The number may be negative indicating a relative
                   previous group and may optionally be wrapped in
                   curly brackets for safer parsing.
  \g{name}  [5]  Named backreference
  \k<name>  [5]  Named backreference
  \k'name'  [5]  Named backreference
  \k{name}  [5]  Named backreference
  \K        [6]  Keep the stuff left of the \K, don't include it in $&
  \N        [7]  Any character but \n.  Not affected by /s modifier
  \v        [3]  Vertical whitespace
  \V        [3]  Not vertical whitespace
  \h        [3]  Horizontal whitespace
  \H        [3]  Not horizontal whitespace
  \R        [4]  Linebreak

=over 4

=item [1]

See L<perlrecharclass/Bracketed Character Classes> for details.

=item [2]

See L<perlrecharclass/POSIX Character Classes> for details.

=item [3]

See L<perlunicode/Unicode Character Properties> for details

=item [4]

See L<perlrebackslash/Misc> for details.

=item [5]

See L</Capture groups> below for details.

=item [6]

See L</Extended Patterns> below for details.

=item [7]

Note that C<\N> has two meanings.  When of the form C<\N{I<NAME>}>, it
matches the character or character sequence whose name is I<NAME>; and
similarly
when of the form C<\N{U+I<hex>}>, it matches the character whose Unicode
code point is I<hex>.  Otherwise it matches any character but C<\n>.

=item [8]

See L<perlrecharclass/Extended Bracketed Character Classes> for details.

=back

=head3 Assertions

Besides L<C<"^"> and C<"$">|/Metacharacters>, Perl defines the following
zero-width assertions:
X<zero-width assertion> X<assertion> X<regex, zero-width assertion>
X<regexp, zero-width assertion>
X<regular expression, zero-width assertion>
X<\b> X<\B> X<\A> X<\Z> X<\z> X<\G>

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.720 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )