Skip to content

Commit

Permalink
Small revision for #2887
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Jul 7, 2019
1 parent f860bf5 commit 4bff7ff
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions doc/Language/regexes.pod6
Expand Up @@ -13,7 +13,7 @@ matching those patterns to actual text.
=head1 X<Lexical conventions|quote,/ /;quote,rx;quote,m>
Perl 6 has special syntax for writing regexes:
Perl 6 has special syntax for literal regexes:
m/abc/; # a regex that is immediately matched against $_
rx/abc/; # a Regex object; allow adverbs to be used before regex
Expand All @@ -22,7 +22,7 @@ Perl 6 has special syntax for writing regexes:
For the first two examples, delimiters other than the slash can be used:
m{abc};
rx{abc};
rx[abc];
Note that neither the colon nor round parentheses can be delimiters; the colon
is forbidden because it clashes with adverbs, such as C<rx:i/abc/>
Expand All @@ -36,13 +36,17 @@ Example of difference between C<m/ /> and C</ /> operators:
$match = m/.+/; say $match; say $match.^name; # OUTPUT: «「abc」␤Match␤»
$match = /.+/; say $match; say $match.^name; # OUTPUT: «/.+/␤Regex␤»
Whitespace in regexes is generally ignored (except with the C<:s> or,
Whitespace in literal regexes is generally ignored (except with the C<:s> or,
completely, C<:sigspace> adverb).
Comments work within a regular expression:
/ word #`(match lexical "word") /
as long as the syntax for
[embedded comments](/language/syntax#Multi-line_/_embedded_comments), with a
backtick and enclosing braces, is usesd.
=head1 Literals
The simplest case for a regex is a match against a string literal:
Expand All @@ -57,7 +61,7 @@ to match a colon), or be within quotes:
/ 'two words' /; # matches 'two words' including the blank
/ "a:b" /; # matches 'a:b' including the colon
/ '#' /; # matches a hash character
/ \# /; # matches a hash character
Strings are searched left to right, so it is enough if only part of the string
matches the regex:
Expand All @@ -70,8 +74,8 @@ matches the regex:
say $/.to; # OUTPUT: «22␤»
};
Match results are stored in the C<$/> variable and are also returned from
the match. The result is of type L<Match|/type/Match> if the match was
Match results are always stored in the C<$/> variable and are also returned from
the match. They are both of type L<Match|/type/Match> if the match was
successful; otherwise it is L<Nil|/type/Nil>.
Expand Down

0 comments on commit 4bff7ff

Please sign in to comment.