Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Regex to add space after punctuation sign

by Abigail-II (Bishop)
on Jan 08, 2004 at 09:58 UTC ( #319770=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Regex to add space after punctuation sign
in thread Regex to add space after punctuation sign

Evaluating $1 || "$2 " means you get $1 if $1 is true (which means, anytime \d[.,]\d matches), otherwise you get $2 (the punctation character), followed by a space.

I would handle end-of-line processing as follows:

s/(\d[,.]\d)|([^\w\s])(?=\S)/$1 || "$2 "/ge;
A single positive look-ahead is, IMO, more clear than two negative look-aheads.

Abigail


Comment on Re: Regex to add space after punctuation sign
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Regex to add space after punctuation sign
by dda (Friar) on Jan 08, 2004 at 10:07 UTC
    Thank you. You are the best!

    --dda

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (16)
As of 2015-07-30 15:27 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 (272 votes), past polls