@@ -13,7 +13,7 @@ matching those patterns to actual text.
13
13
14
14
= head1 X < Lexical conventions|quote,/ /;quote,rx;quote,m >
15
15
16
- Perl 6 has special syntax for writing regexes:
16
+ Perl 6 has special syntax for literal regexes:
17
17
18
18
m/abc/; # a regex that is immediately matched against $_
19
19
rx/abc/; # a Regex object; allow adverbs to be used before regex
@@ -22,7 +22,7 @@ Perl 6 has special syntax for writing regexes:
22
22
For the first two examples, delimiters other than the slash can be used:
23
23
24
24
m{abc};
25
- rx{ abc} ;
25
+ rx[ abc] ;
26
26
27
27
Note that neither the colon nor round parentheses can be delimiters; the colon
28
28
is forbidden because it clashes with adverbs, such as C < rx:i/abc/ >
@@ -36,13 +36,17 @@ Example of difference between C<m/ /> and C</ /> operators:
36
36
$match = m/.+/; say $match; say $match.^name; # OUTPUT: «「abc」Match»
37
37
$match = /.+/; say $match; say $match.^name; # OUTPUT: «/.+/Regex»
38
38
39
- Whitespace in regexes is generally ignored (except with the C < :s > or,
39
+ Whitespace in literal regexes is generally ignored (except with the C < :s > or,
40
40
completely, C < :sigspace > adverb).
41
41
42
42
Comments work within a regular expression:
43
43
44
44
/ word #`(match lexical "word") /
45
45
46
+ as long as the syntax for
47
+ [embedded comments](/language/syntax#Multi-line_/_embedded_comments), with a
48
+ backtick and enclosing braces, is usesd.
49
+
46
50
= head1 Literals
47
51
48
52
The simplest case for a regex is a match against a string literal:
@@ -57,7 +61,7 @@ to match a colon), or be within quotes:
57
61
58
62
/ 'two words' /; # matches 'two words' including the blank
59
63
/ "a:b" /; # matches 'a:b' including the colon
60
- / '#' /; # matches a hash character
64
+ / \# /; # matches a hash character
61
65
62
66
Strings are searched left to right, so it is enough if only part of the string
63
67
matches the regex:
@@ -70,8 +74,8 @@ matches the regex:
70
74
say $/.to; # OUTPUT: «22»
71
75
};
72
76
73
- Match results are stored in the C < $/ > variable and are also returned from
74
- the match. The result is of type L < Match|/type/Match > if the match was
77
+ Match results are always stored in the C < $/ > variable and are also returned from
78
+ the match. They are both of type L < Match|/type/Match > if the match was
75
79
successful; otherwise it is L < Nil|/type/Nil > .
76
80
77
81
0 commit comments