in reply to Regex boundary match

I think I may have found a way to do it:

$test =~ s{\b(test)\b([^\-]|$)}{change_for_url($1,$2)}eg;

Can anyone see any possible issues with that?

Replies are listed 'Best First'.
Re^2: Regex boundary match
by LanX (Saint) on Feb 08, 2020 at 14:10 UTC
    > Can anyone see any possible issues with that?

    Well, maybe not in this case, but this ([^\-]|$) will consume a position.

    This can become an issue if you start combining with following matches.

    That's why I recommended a "lookahead assertion" which is zero width.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Cool thanks - I'll go with your suggestion then :) Much appreciated