Thanks, Rob! I just sent out my proposed solution for 1.b and 1.c, and they basically match yours. Makes me feel good.
Thanks for the one-step way to write it, too. By the way, do you have any array-less way to do 2 or 3 in the original post? 2 was to count the number of colon-delimited substrings without using an array; 3 was to compare one string to another and count the number of colon-delimited substrings that match in the same positions. For example, these two strings: string1 = :L000:W000:M260:M:B297: string2 = :M260:W000:B601: would have only one match -- W000. The M260 is present in both, but not in the same position, a "position" being the order of the substrings within the main string. 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 11:23 AM Scott E Robinson wrote: > 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. Sorry, I would say I'm having a bad day, but I'm not - I have no excuse! > b. remove all but the single-character and all-numeric > substrings and leave the rest alone? my @wanted = $string =~ /\b(\w|\d+)\b/ig; print "@wanted\n"; output M 8 > 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. my $string = ':1:12:123:1234:A:AA:AAA:AAAA:A1:A11:A111:'; my @wanted = $string =~ /\b(\w\w?|\d+)\b/ig; print "@wanted\n"; output 1 12 123 1234 A AA A1 > 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. It has to go /via/ a list, but you can do it in one step without using an array like this: my $string = ':B520:L201:M:M260:8:G607:'; my $subset = join ':', '', $string =~ /\b(\w\w?|\d+)\b/ig, ''; print $subset; output :M:8: Is that any better? :-) 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]