***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.
$foo = "";
if ($foo =~ /^[a]*$/) {
print "Match\n";
}
...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 = "1";
And to finalize my question (which is all about not TRULY understanding how anchors are changing the semantics), why will
$foo = "1";
if ($foo =~ /^[a]*/) {
print "Match\n";
}
.....print "Match".
What are these anchors doing in combination with the '*'?
Thanks in advance for any assistance.
Chris
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.