in reply to Re: Another regexp question
in thread Another regexp question
In asking my question for clarification I belive I have answered myself but anyway:
Can I have some clarification on the wonderful line:
As I understand it the brackets are use to return the values as $1, $2 .. $9my %prices = $str =~ m/((?:$animal)s?)\s(?:is|are)\s(\$\d+)/g;
It looks like (?: .. ) is something special and is not returning a numbered variable so all we get out are two variables $1 and $2 used respectively in the hash as the key and value?
I have often wanted to check to see if a string contains one of multiple sub-strings.. I assume I could do it like this:
Woo Hoo!use strict; my $something = 'This is a bang of a bing thing'; if($something =~ m/((?:bing|bong|bang))/i) { print "Found '$1' in '$something'\n"; }
It returned the first one found.. which is fair.. I wonder if this could return all matches found, in this case 'band' and 'bing'?Found 'bang' in 'This is a bang of a bing thing'
And could I check for a string contain anything from a list?
naturally does not work :-(... my @list = qw / bing bong bang /; if($something =~ m/(?:@list)/i) ...
thanks
___ /\__\ "What is the world coming to?" \/__/ www.wolispace.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Another regexp question
by Roger (Parson) on Nov 20, 2003 at 04:32 UTC | |
by wolis (Scribe) on Nov 21, 2003 at 03:45 UTC | |
by Roger (Parson) on Nov 21, 2003 at 03:53 UTC | |
by davido (Cardinal) on Nov 21, 2003 at 04:01 UTC | |
by wolis (Scribe) on Nov 24, 2003 at 02:54 UTC |