laziness, impatience, and hubris | |
PerlMonks |
Re: Re: compare stdin for a numberby Vautrin (Hermit) |
on Mar 12, 2004 at 21:00 UTC ( [id://336265]=note: print w/replies, xml ) | Need Help?? |
I know that the first time I was learning about regular expressions, "do ___" was much less helpful to me if it didn't include an explanation of why it should be done. I am including one here for completeness. The following code
This is because {}s can contain 2 numbers seperated by a comma. The number on the left is the minimum number of the charachters (or things). The number on the right is the maximum number of charachters (or things). The charachter or thing is whatever is to the left of the {}s. Of course, the reason the original regular expression will still work is the ^ and $ charachter mean "beginning of a line" and "end of a line", respectively. So my regular expression says "at least 5 digits but not more then 5 digits which start on the beginning of a line and end at the end of a line" while the original regular expression says "At least 5 digits between the beginning and end of a line -- and possibly more". Of course, the thing we have to pay attention to here is that mine would fail if we tried to match the string "Foo\n12345\nBar" This is because it fits all the constraints of the regular expression. However, because of the angle brackets <> -- which reads in a single line at a time, you know you can only have one line. Update: Thanks for pointing out my mistake Tom Want to support the EFF and FSF by buying cool stuff? Click here.
In Section
Seekers of Perl Wisdom
|
|