Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expand on negated char classes. Closes #40.
  • Loading branch information
moritz committed Jan 15, 2015
1 parent 470b94a commit c5c4e68
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/Language/regexes.pod
Expand Up @@ -284,6 +284,24 @@ write between the C< [ ] > is the backslashed forms for character classes.
/ <[02468]>
# because the first one also contains "weird" unicodey digits
To negate a character class, put a C<-> after the opening angle:
say 'no quotes' ~~ / <-[ " ]> + /; # matches characters except "
A common pattern for parsing quote-delimited strings involves negated
character classes:
say '"in quotes"' ~~ / '"' <-[ " ]> * '"'/;
This first matches a quote, then any characters thare aren't quotes, and then
a quote again. The meaning of C<*> and C<+> in the examples above are
explained in L<section Quantifier|#Quantifier>.
Just as you can use the C<-> for both set difference and for negation of a
single value, you can also explicitly put a C<+> in front:
/ <+[123]> / # same as <[123]>
=head1 Quantifier
A quantifier makes a preceding atom match not exactly once, but rather a
Expand Down

0 comments on commit c5c4e68

Please sign in to comment.