Skip to content

Commit

Permalink
Improve section Literals of Regex
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun committed Apr 26, 2018
1 parent b986059 commit eeef11c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions doc/Language/regexes.pod6
Expand Up @@ -6,7 +6,7 @@
X<|Regular Expressions>
Regular expressions, I<regexes> for short, are a sequence of characters that
Regular expressions, regexes for short, are a sequence of characters that
describe a pattern of text. Pattern matching is the process of matching
those patterns to actual text.
Expand All @@ -23,8 +23,8 @@ For the first two examples, delimiters other than the slash can be used:
m{abc};
rx{abc};
Note that neither the colon C<:> nor round parentheses can be delimiters;
the colon is forbidden because it clashes with adverbs, such as C<rx:i/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/>
(case insensitive regexes), and round parentheses indicate a function call
instead.
Expand All @@ -39,7 +39,7 @@ Comments work within a regular expression:
The simplest case for a regex is a match against a string literal:
if 'properly' ~~ m/ perl / {
if 'properly' ~~ / perl / {
say "'properly' contains 'perl'";
}
Expand All @@ -51,20 +51,20 @@ to match a colon), or be within quotes:
/ "a:b" /; # matches 'a:b' including the colon
/ '#' /; # matches a hash character
Strings are searched left to right, so it's enough if only
part of the string matches the regex:
Strings are searched left to right, so it is enough if only part of the string
matches the regex:
if 'abcdef' ~~ / de / {
say ~$/; # OUTPUT: «de␤»
say $/.prematch; # OUTPUT: «abc␤»
say $/.postmatch; # OUTPUT: «f␤»
say $/.from; # OUTPUT: «3␤»
say $/.to; # OUTPUT: «5␤»
if 'Life, the Universe and Everything' ~~ / and / {
say ~$/; # OUTPUT: «and␤»
say $/.prematch; # OUTPUT: «Life, the Universe␤»
say $/.postmatch; # OUTPUT: « Everything␤»
say $/.from; # OUTPUT: «19␤»
say $/.to; # OUTPUT: «22␤»
};
Match results are stored in the C<$/> variable and are also returned from
the match. The result is of L<type Match|/type/Match> if the match was
successful; otherwise it's L<Nil|/type/Nil>.
the match. The result is of type L<Match|/type/Match> if the match was
successful; otherwise it is L<Nil|/type/Nil>.
=head1 Wildcards and character classes
Expand Down

0 comments on commit eeef11c

Please sign in to comment.