Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^5: phrase match

by JadeNB (Chaplain)
on Dec 13, 2009 at 18:29 UTC ( #812605=note: print w/replies, xml ) Need Help??

in reply to Re^4: phrase match
in thread phrase match

Thanks for pointing out the error in my ‘fixed’ code!

$sentence =~ s/(^| )($phrases_re)( |$)/$1#$2#$3/g for 0, 1;

I wanted to point out a non-error in your correction above, since it took me a minute to understand what its purpose was: If you just did the global replacement without the for modifier, then you'd have the same problem that Crackers2 pointed out with my original, that overlapping matches wouldn't be handled (because the leading space of the trailing match would already have been gobbled up by the trailing space of the leading space). If I'm understanding correctly, then the for 0, 1 is just making another pass to pick up any matches that we missed this way.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2021-04-16 21:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found