Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: string substitution

by AnomalousMonk (Chancellor)
on Dec 04, 2010 at 12:17 UTC ( #875364=note: print w/replies, xml ) Need Help??

in reply to string substitution

... why output is "&& &" but not "&&&"?

After the first match on  '& &' (which is replaced with '&&'), the 'match point' in the string is sitting just after the second '&' and just before the second space. The regex pattern needs at least three characters to match, and at that point there remain only two characters in the string.

In general, the regex of the OP will only match successive triplets of  '& &' leaving a single  \s between each substituted  '&&' pair because after each match the regex engine must scan forward to find, at the very least, another  \W\s\W triplet. (Heed Corion's caution that  \W includes all  \s characters!)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://875364]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2018-07-17 06:23 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (355 votes). Check out past polls.