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

Re: Regex to add space after punctuation sign

by Aragorn (Curate)
on Jan 08, 2004 at 09:23 UTC ( #319760=note: print w/replies, xml ) Need Help??

in reply to Regex to add space after punctuation sign

I found a solution without using look-behind, which has the limitation of not being able to match variable length strings (so /(?<!\t*)foo)/ does not work).
#!/usr/local/bin/perl use strict; while (my $str = <DATA>) { chomp($str); $str =~ s/(\d+[.,]\d+ # Substitute a (simple) number ... | # or ... [^.,\d ]+) # something without periods, comma's, # digits or spaces ... ((?!$)[.,]?) # followed by a period or comma, if # possible, but not when at the end of # the line ... /$1$2 /gx; # by the number or string, followed by # the found period or comma, and a # trailing space print "<$str>\n"; } __DATA__ 1,2,a,b a,1,b,2, 1,21,a,b,word,d.3,4.5.6 __END__ <1,2, a, b> <a, 1,b, 2,> <1,21, a, b, word, d. 3,4. 5.6>

In addition to the on-line documentation, you could check out Mastering Regular Expressions, 2nd Edition.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-05-27 18:43 GMT
Find Nodes?
    Voting Booth?