cbro has asked for the wisdom of the Perl Monks concerning the following question:
***RESOLVED: Thank you everybody for your replies/help. Also, thanks for dealing with the stupid example :P The point was understanding how the anchors and '*' were interacting, and everybody's responses helped clarify. Much obliged.***
Good Afternoon,
I'm finding myself in a semantics battle against myself, and I'm losing. I'm trully hoping somebody can smack some sense into me here.
I speak the regex /^[a]*$/ as, "A line beginning and ending with zero or more characters in the set {a}".
With that, I understand how an empty string will match
e.g.
...prints "Match". So, if this regex does translate to, "A line beginning and ending with zero or more letters in the set/class {a}"...then why doesn't "Match" get printed if I set$foo = ""; if ($foo =~ /^[a]*$/) { print "Match\n"; }
And to finalize my question (which is all about not TRULY understanding how anchors are changing the semantics), why will$foo = "1";
.....print "Match". What are these anchors doing in combination with the '*'? Thanks in advance for any assistance. Chris$foo = "1"; if ($foo =~ /^[a]*/) { print "Match\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex Semantics
by ikegami (Patriarch) on Oct 04, 2006 at 21:12 UTC | |
Re: Regex Semantics
by wazzuteke (Hermit) on Oct 04, 2006 at 21:11 UTC | |
Re: Regex Semantics
by GrandFather (Saint) on Oct 04, 2006 at 21:16 UTC | |
Re: Regex Semantics
by diotalevi (Canon) on Oct 04, 2006 at 21:13 UTC | |
Re: Regex Semantics
by ysth (Canon) on Oct 04, 2006 at 21:58 UTC | |
by ikegami (Patriarch) on Oct 04, 2006 at 23:57 UTC |
Back to
Seekers of Perl Wisdom