in reply to regular expression (search and destroy)
Here are my 2 cents. This code would do what you are asking, but wouldn't handle other problems like a " in the quoted string.
#!/usr/bin/perl -w my $line = '121212, "Simpson, Bart", Springfield<br>'; print "Before: $line\n"; $line =~ s/"(.*?),(.*?)"/$1_$2/; print "After: $line\n";
The output is:
Before: 121212, "Simpson, Bart", Springfield<br> After: 121212, Simpson_ Bart, Springfield<br>
To explain, adding a ? after *, as in .*? causes minimal matching. It will match the first ", then as few characters as possible, then a comma, then more of the same until another " is found. It all gets replaced with the s///.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: regular expression (search and destroy)
by sauoq (Abbot) on Nov 12, 2003 at 21:42 UTC |