Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Regex boundary match (updated demo code)

by AnomalousMonk (Bishop)
on Feb 08, 2020 at 15:55 UTC ( #11112630=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regex boundary match (updated demo code)
in thread Regex boundary match

I ended up with ([^\-]). ... difference?

It depends on exactly what you want.  ([^\-]) requires a character match and consumes a character. As LanX pointed out,  ([^\-]|$) consumes a character if it can. Neither seem to do what you want:

c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'test atest atested tested test- -test test .test test. test' +; ;; $s =~ s/\b(test)([^-])/DONE/g; print qq{'$s'}; " 'DONEatest atested DONEd test- -DONEDONE.DONEDONE test' c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'test atest atested tested test- -test test .test test. test' +; ;; $s =~ s/\b(test)([^-]|$)/DONE/g; print qq{'$s'}; " 'DONEatest atested DONEd test- -DONEDONE.DONEDONE DONE'
Maybe this does:
c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'test atest atested tested test- -test test .test test. test' +; ;; $s =~ s/\b(test)(?!-)\b/DONE/g; print qq{'$s'}; " 'DONE atest atested tested test- -DONE DONE .DONE DONE. DONE'

Update: Just noticed from the timestamps that ultranerds already decided to go with LanX's suggestion. :)


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11112630]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2020-05-25 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (143 votes). Check out past polls.

    Notices?