|
|
| Perl Monk, Perl Meditation | |
| PerlMonks |
Re: How does this regex not match?by 7stud (Deacon) |
| on Feb 13, 2010 at 11:54 UTC ( [id://823007]=note: print w/replies, xml ) | Need Help?? |
|
If you are having trouble figuring out what the previous responses are saying, the regex my_stuff[1] is equivalent to the regex my_stuff1, which does not appear in your original string. The regex my_stuff[1] says to look for the string 'my_stuff' followed by one of the characters specified in the brackets. Because you only have one character specified in the brackets, the regex is equivalent to mystuff1. Here is an example of how brackets can prove useful in a regex:
In order to literally match any of the regex characters that have special meaning (e.g. * . ?), you have to 'escape' the character. You 'escape' a special character with a '\', which tells perl to ignore the special regex meaning of the character. As it turns out, you only have to escape the opening bracket, and then perl knows the closing bracket is to be interpreted as a literal bracket:
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||