Perl regex: string literal containing metacharacters as variable for match
expression
I need to define a string literal as a variable which will be later used
as a match expression.
I want my variable $regex_op to match the string alt_id: ID: as well as
the string id: ID:.
my $regex_op = "(id|alt_id):\sID:";
my $searchword = "4";
Later on, I'm joining the variables in a regular expression:
/^($regex_op)($searchword)/m
Unfortunately, the whitespace wildcard \s is an "Unrecognized escape \s
passed through". The problem apparently consists in the string literal
containing backslashes (which are needed as part of the regex later on!).
Any ideas how to solve this?
No comments:
Post a Comment