How can I convert a string to a regular expression that matches itself in Perl?
I have a set of strings like these:
Enter your selection:
Enter Code
From http://www.regular-expressions.info/characters.html :
there are 11 characters with special meanings: the opening square bracket [
, the backslash \
, the caret ^
, the dollar sign $
, the period or dot .
, the vertical bar or pipe symbol |
, the question mark ?
, the asterisk or star *
, the plus sign +
, the opening round bracket (
and the closing round bracket )
In Perl (and PHP) there is a special function quotemeta that will escape all these for you.