We don't bite newbies here... much | |
PerlMonks |
Re: Regular expressionsby tlm (Prior) |
on Apr 13, 2005 at 13:26 UTC ( [id://447366]=note: print w/replies, xml ) | Need Help?? |
What you want is What you wrote matches only strings that contain the substring 'a-zA-Z' in them. You need to enclose ranges like 'A-Z' within [ ] for them to be interpreted as character classes. Also, by anchoring the regexp (with ^ and $1) you ensure that the entire string must match. The last thing is that you need that quantifier + so that one or more characters will match; without it, the only strings that will match are those consisting of a single letter. 1Some people prefer to use \z instead of $ for the end-of-string anchor, because $ doesn't unconditionally match the end of the string; indeed, it ignores one optional trailing newline. I think of $ as basically shorthand for /\n?\z/... Well, it's more complicated than that, because the meaning of $ changes in the presence of the /m modifier, but not so for /\n?\z/... A lot of ins, a lot of outs, a lot of what-have-yous, a lot of strands to keep in the ol' duder's head... Update: In my original reply, I focused on the why the regexp was not matching, and failed to notice that you were using $1 later on. I fixed the regexp to reflect this. Sorry for the confusion. the lowliest monk
In Section
Seekers of Perl Wisdom
|
|