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

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