Rob, I found versions of 1.b. and 1.c. that seem to work, using the '|' operator. They're probably not the most elegant:
Given a colon-delimited string such as my $string = ':B520:L201:M:MM:M260:8:88:G607:'; 1.b. Keep single-letter substrings and also any all-numeric substrings: my @wanted = $string =~ /\b(\w|\d*)\b/ig; 1.c. Keep only single- and double-letter substrings and also any all-numeric substrings: my @wanted = $string =~ /\b[a-z]\w?\b|\b[0-9]+\b/ig; I still wonder if the array is necessary. Thanks, Scott Scott E. Robinson SWAT Team UTC Onsite User Support RR-690 -- 281-654-5169 EMB-2813N -- 713-656-3629 ----- Forwarded by Scott E Robinson/U-Houston/ExxonMobil on 03/24/03 11:20 AM ----- Scott E Robinson To: "Rob Dixon" <[EMAIL PROTECTED]> cc: [EMAIL PROTECTED] 03/24/03 11:06 AM Subject: Re: Searching for the right regular expressions(Document link: Scott E Robinson) Hi, Rob! Amazing how quickly you coded those up! 1.a. works great. 1.b. doesn't quite work yet. The revised version (my @wanted = $string =~ /\b\w\d*\b/ig;) seems to let everything pass through it. 1.c. - Sorry I wasn't clear. I need to keep the all-numeric substrings as well as keeping the single- and double-letter substrings. Your code kept the double-letter ones beautifully, though. Does the output have to go to an array? I can just reassemble it to a single string (either delimited by colons or single blanks) as you showed, but wondered if it can be skipped for greater efficiency. Thanks, Scott Scott E. Robinson SWAT Team UTC Onsite User Support RR-690 -- 281-654-5169 EMB-2813N -- 713-656-3629 "Rob Dixon" <[EMAIL PROTECTED] To: [EMAIL PROTECTED] .co.uk> cc: Subject: Re: Searching for the right regular expressions 03/24/03 10:08 AM 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]