in reply to Re: Regular Expression Question
in thread What happens with empty $1 in regular expressions? (was: Regular Expression Question)
However, a failed match returns false, so if you removed the , 1's from each of those, you wouldn't see the line for "=".#!/usr/bin/perl -w if ("abc" =~ /(\w+)/, 1) { print "abc => $1\n" } { print "local: $1\n"; if ("ghi" =~ /\w+/, 1) { print "ghi => $1\n" } if ("def" =~ /(\w+)/, 1) { print "def => $1\n" } if ("[=]" =~ /(\w+)/, 1) { print "[=] => $1\n" } } print "general: $1\n"; __END__ abc => abc local: abc Use of uninitialized value at regexes line 6. ghi => def => def [=] => def general: abc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Regular Expression Question
by ZZamboni (Curate) on Feb 28, 2001 at 19:40 UTC |