note
Aragorn
I found a solution without using look-behind, which has the limitation of not being able to match variable length strings (so <code>/(?<!\t*)foo)/</code> does not work).
<code>
#!/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>
</code>
<p/>
In addition to the on-line documentation, you could check out [isbn://0596002890|Mastering Regular Expressions, 2nd Edition].
<p/>
Arjen
319742
319742