Hi. Rading your post again, it looks like I kinda screwed up. Lets try again!
Rob Dixon wrote: > Hi Scott > > Scott E Robinson wrote: > > Dear Perl experts, > > > > I'm trying to find the right regular expressions to do some simple > > (?) string processing. Can anyone tell me how to do these? > > > > 1. Given a string consisting of substrings delimited by colons, > > such as :B520:L201:M:M260:8:G607:, > > my $string = ':B520:L201:M:M260:8:G607:'; > > > how can I > > a. remove the single-character and all-numeric substrings (M > > and 8 in this example), leaving the rest alone? > > This is an array of all the wanted substrings: > > my @wanted = $string =~ /[a-z]\w+/ig; > print "@wanted\n"; > > output > > B520 L201 M260 G607 I think that's right, although it assumes that the values that aren't all-numeric start with an alpha. > > b. remove all but the single-character and all-numeric > > substrings and leave the rest alone? > > This is an array of all the wanted substrings: > > my @wanted = $string =~ /\b\w\b/ig; > print "@wanted\n"; > > output > > M 8 Right result, but fails to find '88'. Try: my @wanted = $string =~ /\b\w\d*\b/ig; > > c. remove all but single- or double-character substrings and > > all-numeric substrings and leave the rest alone? > > This is an array of all the wanted substrings: > > my @wanted = $string =~ /\b[a-z]\w?\b/ig; > print "@wanted\n"; > > output > > M This is right, I think. > (Note that this won't find '8M', but your data doesn't look like > that will come up.) > That's more like it! Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]