in reply to Re: Regex: match a word stem plus an optional suffix from a group
in thread Regex: match a word stem plus an optional suffix from a group

Thanks, I found the typo: in my regex, the last suffix was "an" not just "n", so it didn't match "Russian". Now it does. Yes, my variable starts with a $. Now I also put it in squiggly brackets for clarity ${wordstem}.
  • Comment on Re^2: Regex: match a word stem plus an optional suffix from a group

Replies are listed 'Best First'.
Re^3: Regex: match a word stem plus an optional suffix from a group
by Your Mother (Archbishop) on Jul 21, 2022 at 02:40 UTC

    You should also escape interpolated stuff in regexen. \Q${wordstem}\E in this case. If you don’t, you can end up with really confusing bugs and, depending on Perl version, a malicious regex that can be a DoS attack. I would encourage you to use /x to improve readability. Something like–

    / \b \Q${stem}\E (?: s | 's | n )? \b /xi