Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Please tell me what might be wrong with my regex:
My string is: $string = "hello = 1234ab;cat;dog;4892";
I want to grab everything between the 2nd the and 3rd semicolons...
The $substring should print out dog, but instead it grabs all the string.my $semiColon=2; if ( $string =~ /hello.*=(\s*.*;\s*){$semiColon}(\s*.*;\s*).*/i ) my $substring = $2;
Thanks a lot in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex picking out a particular string
by BUU (Prior) on Feb 04, 2005 at 02:10 UTC | |
by Anonymous Monk on Feb 04, 2005 at 13:21 UTC | |
by nobull (Friar) on Feb 04, 2005 at 20:07 UTC | |
|
Re: regex picking out a particular string
by Roy Johnson (Monsignor) on Feb 04, 2005 at 01:59 UTC | |
|
Re: regex picking out a particular string
by gube (Parson) on Feb 04, 2005 at 04:00 UTC | |
|
Re: regex picking out a particular string
by nobull (Friar) on Feb 04, 2005 at 20:17 UTC |