Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your first problem is that you need three (possibly four) cases in your alternation, not two.</p> <ul> <li><code>/\breverse!(?:\s|$)/</code> reverse! by itself</li> <li><code>/\bpush\b/</code> push by itself</li> <li><code>/\breverse!push\b/</code> together</li> <li><code>/\bpushreverse!(?:\s|$)/</code> this is the possible case</li> </ul> <p>Your second problem is that a <code>\b</code> won't match after a <code>"!"</code> because it is not a <code>\w</code>. Here is what <a href="http://perldoc.perl.org/perlre.html" rel="nofollow noreferrer">Perl 5 has to say about <code>\b</code></a>, you may want to consult your docs to see if they agree:</p> <blockquote> <p>A word boundary ("\b") is a spot between two characters that has a "\w" on one side of it and a "\W" on the other side of it (in either order), counting the imaginary characters off the beginning and end of the string as matching a "\W". (Within character classes "\b" represents backspace rather than a word boundary, just as it normally does in any double-quoted string.)</p> </blockquote> <p>So, the regex that you need is something like</p> <pre><code>/ \b ( reverse!push | reverse! | push ) (?: \s | \b | $ )+ /gx; </code></pre> <p>I left out the <code>/s</code> because there are not periods in this regex, so treat as single line makes no sense. If <code>/s</code> doesn't mean treat as a single line in your engine you should probably add it back. Also, you should read up on how your engine handles alternation. I know in Perl 5 to get the right behaviour you must arrange the items this way (otherwise reverse! would always win over reverse!push).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload