in reply to RE: (Ovid) Re: Transpose some spaces to commas in a string
in thread Transpose some spaces to commas in a string

Untested:
my $testvar = "Bob Q Smith bsmith 00001234567 5/1/00 12:00:00"; $testvar =~ s/ \s # a whitespace character (space, tab, etc) ( # Capture to $1 \w+ # one or more word characters (e.g. bsmi +th) ) \s # a whitespace character ( # Capture to $2 \d+ # one or more digits ) \s # a whitespace character /,$1,$2,/x;
If your data is relatively clean, I think that should work. It relies on you knowing that the first digits you encounter are going to be your serial number and immediately preceding them are some letters. From there, it's pretty straightforward. There are many different ways to write this regex and this may not be the best, but it's fairly clear.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

Replies are listed 'Best First'.
RE: (Ovid) RE(3): Transpose some spaces to commas in a string
by Albannach (Monsignor) on Sep 29, 2000 at 21:41 UTC
    Nice one as that works on names with zero or more middle initials, and isn't bothered by capitalized usernames either (as my quick attempt was).