On 15/05/18 13:49, ToddAndMargo wrote: > Hi All, > > This should be a "no". What am I doing wrong? > > $ perl6 -e 'my $x="rd"; if $x~~/<[rc]+[a]+[b]+[.]>/ {say > "yes"}else{say "no"}' > yes > > > Many thanks, > -T
what you've put in your regex here is a character class combined of four individual ones "added together"; it matches a single letter that is either an "r", a "c", an "a", a "b", or a ".". Character classes always match only a single character, if you want it to match more, you will have to use a quantifier, like "+", "*", or "**". Since your regex is not anchored, it will accept any of those characters in any spot, so strings like "hello a" will match, too. It seems like what you want is actually this: /rc | a | b | "."/ which matches if either "rc", "a", "b" or "." exist somewhere in the string. If you want to accept only if the full string is "rc", "a", "b" or ".", you'll have to put anchors in the front and back, and put brackets around the inner part, so that the ^ and $ refer to the whole alternation, not just the ^ to the first variant and $ to the last variant.