Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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.

Arjen

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2016-09-25 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (463 votes). Check out past polls.