in reply to What happens with empty $1 in regular expressions? (was: Regular Expression Question)
Interestingly, your last code snippet will do the right thing if you remove the part after the && (and an extra opening parenthesis you seem to have there), because $1 and $2 will only be used when there is a match, and in that case they will contain either the strings they matched, or undef if their respective subexpressions didn't match anything.if ($sss =~ /(\d+)/) { # use $1 as you wish } else { # don't! }
--ZZamboni
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regular Expression Question
by japhy (Canon) on Feb 28, 2001 at 19:28 UTC | |
by ZZamboni (Curate) on Feb 28, 2001 at 19:40 UTC |