Please bottom post...
> I think this might work.
>
It might, but doesn't. Some testing would be good before posting
inaccurate responses.
> /\b\d{4}\b/
>
\b is matching on boundaries, so you miss the first set, and the set
with the 'aa' around them, and then there is the set with the '-'....
> 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
>
Out of curiousity based on your description shouldn't it return,
1111:2222:3333:5555:5555:6666:7777:8888
Or do you really mean, you are trying to capture all 4 digit strings
that are not in a string of longer digits? You need to be very explicit
about what you are after. I think (and have tested) that,
my @a = ($foo =~ m'(?<!\d{4})\d{4}(?!\d)'g);
Gives you want you want, though I don't claim to be a regex expert like
others on the list (are experts, rather than claiming). And I *believe*
says, match any 4 digit string not preceded by a 4 digit string and not
followed by a digit.
Works?
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>