perl6 How to make subrule/regex case-insensitive when used in match?

Refresh

February 2019

Views

4 time

0

I am trying to match any keywords in a group. Keywords are in array @b. I am unable to make case-insensitive matches. I have done some testing, and the following script is an example:

> my $line = "this is a test line";
this is a test line

> my @b = < tes lin > ; 
[tes lin]

> my regex a { || @b };
regex a { || @b }

> say $line ~~ m:i/ <a> /    # matching the first as expected
「tes」
 a => 「tes」

> say $line ~~ m:i:g/ <a> /  # matching both as expected
(「tes」
 a => 「tes」 「lin」
 a => 「lin」)

> my @b = < tes LIN > ; 
[tes LIN]
> my regex a { || @b };
regex a { || @b }
> say $line ~~ m:i:g/ <a> /   # should match both "tes" and "LIN" but skips "LIN"
(「tes」
 a => 「tes」)

> my @b = < TES lin >
[TES lin]
> my regex a { || @b }
regex a { || @b }
> say $line ~~ m:i:g/ <a> /   # expect to match both but skips "TES"
(「lin」
 a => 「lin」)

Also, mapping to all lower cases does not work:

> my @b = < TES lin >.lc
[tes lin]
> my regex a { || @b }
regex a { || @b }
> say $line ~~ m:i:g/ <a> /
()

My question is, how should case-insensitivity be handled when a regex/subrule is actually called?

I tried to put :i adverb inside regex a but the resulting matches are futile:

> my regex a { :i || @b }
regex a { :i || @b }
> say $line ~~ m:i:g/ <a> /
(「」
 a => 「」 「」

and then 19 lines of "a => 「」 「」"

 a => 「」)

Thank you very much !!!

lisprog

0 answers