Eugene Barsky
Eugene Barsky

Reputation: 6012

Making character class with modifier symbols in Perl 6

I'd like to make a user-defined character class of "vowels", which will match any literal English vowel letter (a, e, i, o, u) as well as any of these letters with any possible diacritics: ắ ḗ ú̱ å ų̄ ẹ́ etc.

This is what I've tried to do, but it doesn't work:

> my $vowel = / <[aeiou]> <:Sk>* /
/ <[aeiou]> <:Sk>* /
> "áei" ~~ m:g/ <$vowel> /
(「e」 「i」)

Upvotes: 7

Views: 169

Answers (2)

timotimo
timotimo

Reputation: 4329

The reason you can't match a vowel with a combining character using / <[aeiou]> <:Sk>* / is that strings in Perl 6 are operated on at the grapheme level. At that level, ų̄ is already just a single character, and <[aeiou]> being a character class already matches one whole character.

The right solution is, as Håkon pointed out in the other answer, to use the ignoremark adverb. You can put it before the regex like rx:m/ <[aeiou]> / or inside of it, or even turn it on and off at different points with :m and :!m.

Upvotes: 10

H&#229;kon H&#230;gland
H&#229;kon H&#230;gland

Reputation: 40778

You could try use ignoremark:

The :ignoremark or :m adverb instructs the regex engine to only compare base characters, and ignore additional marks such as combining accents.

For your example:

my $vowel = /:m<[aeiou]>/;
.say for "áeikj" ~~ m:g/ <$vowel> /;

Output:

「á」
「e」
「i」

Upvotes: 10

Related Questions