Trouble with m///g
From: Chap Harrison (clh_at_pobox.com)
Date: 09/30/04
- Next message: Rob Hanson: "RE: Trouble with m///g"
- Previous message: Wiggins d Anconia: "Re: GetOptions problems"
- Next in thread: Rob Hanson: "RE: Trouble with m///g"
- Maybe reply: Rob Hanson: "RE: Trouble with m///g"
- Reply: Dave Gray: "Re: Trouble with m///g"
- Maybe reply: Wiggins d Anconia: "RE: Trouble with m///g"
- Maybe reply: Bob Showalter: "RE: Trouble with m///g"
- Reply: Gunnar Hjalmarsson: "Re: Trouble with m///g"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: beginners@perl.org Date: Thu, 30 Sep 2004 09:37:55 -0500
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
- Next message: Rob Hanson: "RE: Trouble with m///g"
- Previous message: Wiggins d Anconia: "Re: GetOptions problems"
- Next in thread: Rob Hanson: "RE: Trouble with m///g"
- Maybe reply: Rob Hanson: "RE: Trouble with m///g"
- Reply: Dave Gray: "Re: Trouble with m///g"
- Maybe reply: Wiggins d Anconia: "RE: Trouble with m///g"
- Maybe reply: Bob Showalter: "RE: Trouble with m///g"
- Reply: Gunnar Hjalmarsson: "Re: Trouble with m///g"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|