Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Regex to add space after punctuation sign

by Roy Johnson (Monsignor)
on Jan 08, 2004 at 17:50 UTC ( #319879=note: print w/ replies, xml ) Need Help??


in reply to Regex to add space after punctuation sign

No alternation, no /e, just soft and pink.

s/(?!\d[.,]\d)(.[^\w\s])(?!\s)/$1 /g;
Update
Just noticed how similar this is to ysth's solution, but his use of lookahead/lookbehind is really advanced.
...and...
Had removed the dot from the group. Need that. (Thanks, dda.)

The PerlMonk tr/// Advocate


Comment on Re: Regex to add space after punctuation sign
Download Code
Replies are listed 'Best First'.
Re: Re: Regex to add space after punctuation sign
by dda (Friar) on Jan 10, 2004 at 20:34 UTC
    Hmm.. Just tried:
    $_ = "1.2.a.b"; s/(?!\d[.,]\d)([^\w\s])(?!\s)/$1 /g; print;
    Prints "1. 2. a. b"

    --dda

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2015-07-31 17:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls