Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Re: Regex to add space after punctuation sign

by dda (Friar)
on Jan 08, 2004 at 09:52 UTC ( #319767=note: print w/replies, xml ) Need Help??

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

Thank you, Abigail. Can you please explain how does the replacement part of your expression work? If I understand correctly, /e evaluates $1 || "$2 " -- that way if $1 is not empty, it should not add second part?


P.S. I added end-of-line processings as was suggested by aragorn:
s/(\d[,.]\d)|([^\w\s](?!\s)(?!$))/$1 || "$2 "/ge;

Replies are listed 'Best First'.
Re: Regex to add space after punctuation sign
by Abigail-II (Bishop) on Jan 08, 2004 at 09:58 UTC
    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.


      Thank you. You are the best!


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2017-11-25 06:55 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (355 votes). Check out past polls.