pat_mc has asked for the wisdom of the Perl Monks concerning the following question:
Hi there, esteemed Monks!
I am having trouble with the upper and lower case backslash escapes in regular expressions and would very much appreciate your help with these.
So far, I thought \l matches lowercase characters, similar to [a-z] would for English text. This is obviously wrong:
This seems to work. An analogous result is obtained for \u
My question is: Can I used those escape characters in a matching pattern as well - and if so, what is their meaning in that context?
Really appreciate your wisdom.
Cheers -
Pat
I am having trouble with the upper and lower case backslash escapes in regular expressions and would very much appreciate your help with these.
So far, I thought \l matches lowercase characters, similar to [a-z] would for English text. This is obviously wrong:
I then thought it acts like an operator to modify substitution strings:$ perl -e '( $a = "hello" ) =~ s/^\l//; print $a' hello
$ perl -e '( $a = "Hello" ) =~ s/(.+)/\l$1/; print $a' hello
This seems to work. An analogous result is obtained for \u
My question is: Can I used those escape characters in a matching pattern as well - and if so, what is their meaning in that context?
Really appreciate your wisdom.
Cheers -
Pat
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to use \l and \u in regex mathing patterns?
by AnomalousMonk (Archbishop) on May 09, 2012 at 16:36 UTC | |
Re: How to use \l and \u in regex mathing patterns?
by MidLifeXis (Monsignor) on May 09, 2012 at 16:31 UTC | |
Re: How to use \l and \u in regex mathing patterns?
by Anonymous Monk on May 09, 2012 at 16:41 UTC | |
Re: How to use \l and \u in regex mathing patterns?
by brx (Pilgrim) on May 09, 2012 at 16:45 UTC | |
by Anonymous Monk on May 09, 2012 at 16:54 UTC | |
by AnomalousMonk (Archbishop) on May 09, 2012 at 17:06 UTC | |
by Anonymous Monk on May 09, 2012 at 17:18 UTC | |
by JavaFan (Canon) on May 09, 2012 at 18:26 UTC | |
Re: How to use \l and \u in regex mathing patterns?
by sundialsvc4 (Abbot) on May 10, 2012 at 12:10 UTC |
Back to
Seekers of Perl Wisdom