Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2018-09-22 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (190 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!