in reply to Regex trouble
Add your MATCH patterns to @pats, enclosing in parenthesis the parts you want. The grep eliminates undef elements in the result of the match, which correspond to those patterns that did not match, and leaves only the matching parts.$float='\d+(?:\.\d+)?'; $int='\d+'; @pats=("r($int)", "rect($float)x($float)", "dounut_s($int)x($int)"); $pat=join("|", @pats); @numbers=grep { defined($_) } ($str =~ /^(?:$pat)$/);
--ZZamboni
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Regex trouble
by cyclone (Novice) on May 17, 2000 at 00:47 UTC | |
by ZZamboni (Curate) on May 17, 2000 at 01:01 UTC |