Hmmm...
m'\b(\d{4})\b'g <1111 2222aa3333 444 55555555 6666 7777-8888> 1111:6666:7777:8888
Doesn't give me 2222 or 3333. I think the problem has to do with where m///g starts on subsequent iterations. The pattern specifies a delimiter for both the start and the end of the target substring, but that means it will want to find an ending delim on iteration n, followed by a beginning delim on iteration n+1.
On Sep 30, 2004, at 9:41 AM, Hanson, Rob wrote:
I think this might work.
/\b\d{4}\b/
Rob
-----Original Message----- From: Chap Harrison [mailto:[EMAIL PROTECTED] Sent: Thursday, September 30, 2004 10:38 AM To: [EMAIL PROTECTED] Subject: Trouble with m///g
Hi,
I'm trying to extract all four-digit numbers from a string in one fell swoop, but I can't seem to come up with the proper regexp. This is my first time using /g in a match so maybe there's a trick I'm missing.
For example, the string
"1111 2222aa3333 444 55555555 6666 7777-8888"
should yield
1111, 2222, 3333, 6666, 7777, 8888.
Here's one attempt that I thought had a reasonable chance.
- - - - - #!/usr/bin/perl -w my $foo = "1111 2222aa3333 444 55555555 6666 7777-8888"; my @a = ($foo =~ m'[\D^](\d{4})[\D$]'g); print "<$foo>\n"; print(join(":",@a)."\n"); - - - - -
<1111 2222aa3333 444 55555555 6666 7777-8888> 2222:3333:6666
Thanks for your consideration, Chap
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>