source: trunk/essentials/dev-lang/perl/pod/perlreref.pod@ 3951

Last change on this file since 3951 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 9.4 KB
Line 
1=head1 NAME
2
3perlreref - Perl Regular Expressions Reference
4
5=head1 DESCRIPTION
6
7This is a quick reference to Perl's regular expressions.
8For full information see L<perlre> and L<perlop>, as well
9as the L</"SEE ALSO"> section in this document.
10
11=head2 OPERATORS
12
13 =~ determines to which variable the regex is applied.
14 In its absence, $_ is used.
15
16 $var =~ /foo/;
17
18 !~ determines to which variable the regex is applied,
19 and negates the result of the match; it returns
20 false if the match succeeds, and true if it fails.
21
22 $var !~ /foo/;
23
24 m/pattern/igmsoxc searches a string for a pattern match,
25 applying the given options.
26
27 i case-Insensitive
28 g Global - all occurrences
29 m Multiline mode - ^ and $ match internal lines
30 s match as a Single line - . matches \n
31 o compile pattern Once
32 x eXtended legibility - free whitespace and comments
33 c don't reset pos on failed matches when using /g
34
35 If 'pattern' is an empty string, the last I<successfully> matched
36 regex is used. Delimiters other than '/' may be used for both this
37 operator and the following ones.
38
39 qr/pattern/imsox lets you store a regex in a variable,
40 or pass one around. Modifiers as for m// and are stored
41 within the regex.
42
43 s/pattern/replacement/igmsoxe substitutes matches of
44 'pattern' with 'replacement'. Modifiers as for m//
45 with one addition:
46
47 e Evaluate replacement as an expression
48
49 'e' may be specified multiple times. 'replacement' is interpreted
50 as a double quoted string unless a single-quote (') is the delimiter.
51
52 ?pattern? is like m/pattern/ but matches only once. No alternate
53 delimiters can be used. Must be reset with L<reset|perlfunc/reset>.
54
55=head2 SYNTAX
56
57 \ Escapes the character immediately following it
58 . Matches any single character except a newline (unless /s is used)
59 ^ Matches at the beginning of the string (or line, if /m is used)
60 $ Matches at the end of the string (or line, if /m is used)
61 * Matches the preceding element 0 or more times
62 + Matches the preceding element 1 or more times
63 ? Matches the preceding element 0 or 1 times
64 {...} Specifies a range of occurrences for the element preceding it
65 [...] Matches any one of the characters contained within the brackets
66 (...) Groups subexpressions for capturing to $1, $2...
67 (?:...) Groups subexpressions without capturing (cluster)
68 | Matches either the subexpression preceding or following it
69 \1, \2 ... The text from the Nth group
70
71=head2 ESCAPE SEQUENCES
72
73These work as in normal strings.
74