[lug] Perl regex question

Bill Thoen bthoen at gisnet.com
Wed Sep 20 13:16:17 MDT 2006


If I have strings like the following:
A,2, 3, 5, 7
F, 8, 9, 1

and I want to turn them into stirngs like these:
A2 A3 A5 A7
F8 F9 F1

using Perl regex, how is this done?  I'm trying something like the 
following:
#!/usr/bin/perl
while (<>) {
  chop;
  s/^[A-Z][, ]+(([0-9])[, ]+[^, ])+/$1$2 /g;
  print "$_\n";
}

But of course, it doesn't work. How does one process a list of items 
like this using Perl's regular expressions?

- Baffled in Boulder





More information about the LUG mailing list