Your first problem is that you need three (maybe four) cases in your rotation, not two.
/\breverse!(?:\s|$)/ reverse! in itself/\bpush\b/ click on its own/\breverse!push\b/ together/\bpushreverse!(?:\s|$)/ this is a possible case
The second problem is that \b will not match after "!" because it is not \w . Here's what Perl 5 says about \b , you can refer to your docs to see if they agree:
The word boundary ("\ b") is the spot between two characters having "\ w" on one side of it and "\ W" on the other side (in any order), counting imaginary characters from the beginning and end of the line in accordance with "\ W". (Inside the character classes, "\ b" is the backspace, not the word boundary, as is usually done on any line with two quotation marks.)
So the regex that you need is like
/ \b ( reverse!push | reverse! | push ) (?: \s | \b | $ )+ /gx;
I left /s because there are no periods in this regex, so it makes no sense to relate to one line. If /s doesnβt mean what to consider as one line in your engine, you should probably add it back. In addition, you should read how your engine handles rotation. I know that in Perl 5 you need to arrange the elements in this way for proper behavior (otherwise the opposite! The opposite will always win!).
source share