Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Quantifier quantifies nothing" but I never asked for a quantifier

Consider the following Perl-flavoured?? (i suppose not?) regex to test if a string is a palindrome:

^((.)(?1)\2|.?)$

try it here.

the following

my regex palindrome {
    ^((.)(?1)\2|.?)$
}

say "$word is a palindrome"
    if $word ~~ /<palindrome>/
    && $word.chars > 1;

gives an error

===SORRY!===
Quantifier quantifies nothing
at /home/cat/projects/perl6/code/misc/words.pl6:6
------>   ^((.)(?⏏1)\2|.?)$
Unrecognized backslash sequence (did you mean $1?)
at /home/cat/projects/perl6/code/misc/words.pl6:6
------>   ^((.)(?1)\2⏏|.?)$

I have a working knowledge of (Python) regexes, and I get what it means when it says "Quantifier quantifies nothing", but I don't get why it says this when I was asking for recursion, not a quantification.

I don't have enough knowledge of Perl to know why it doesn't like the backslash (the other error).

I did try messing around with the syntax and searching around, but as far as I and the internet are concerned, this regex works, and fiddling with it generates various other errors I don't get.

What am I doing wrong?

like image 793
cat Avatar asked Mar 19 '26 01:03

cat


1 Answers

One way to do it is this:

my regex palindrome { (.) <~~> $0 || .? }
say "aba" ~~ /^<palindrome>$/;
like image 62
Christoph Avatar answered Mar 20 '26 14:03

Christoph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!