in reply to more date conversion happiness, part 3
where the ^ says that part of the regex can only match at the beginning of the string and \z says that can match only at the end of the string, so that no unexpected characters are allowed before or after the pattern specified.$str =~ /^\d*[a-z]+\z/i;
Without the anchors, you get /\d*[a-z]+/i which will match any string that has at least one letter somewhere in it, e.g. ";!$#a-+".
(You will often see $ used instead of \z; that will match either at the end of the string or immediately before a newline character at the end of the string; sometimes handy when dealing with unchomped input, but usually not what is actually wanted.)
The meaning of ^ and $ changes when the //m flag is used, see perlre for details.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: more date conversion happiness, part 3
by ctp (Beadle) on Jan 12, 2004 at 03:24 UTC | |
by ysth (Canon) on Jan 12, 2004 at 03:45 UTC | |
by ctp (Beadle) on Jan 12, 2004 at 03:49 UTC |