in reply to Re: Regular Expresssion TroubleShoot Help plz
in thread Regular Expresssion TroubleShoot Help plz

$foo = qq{^snafu^|^foobar^\n}; $foo =~ m/\A(\W) # \A instead of ^ and match first non-word .+? # +? Minimal match everything that isn't in \1 \1(\W) # Match non-word following the 2nd \1 /xms; $TEXT_QUAL = $1; $FIELD_SEP = $2;


Having now found the proper way to attempt to acquire delimiters, the following questions how to utilize these new found delimiters.
Instead of creating one large regex, I'd perfer to store them in scalars, which is the core of this particular problem.
$foo =~ /\G$TEXT_QUAL(.*?)$TEXT_QUAL[$FIELD_SEP\n]/xmsgc;
Fails to work since the qualifiers are metacharacters used in regular expressions.


$foo =~ /\G\$TEXT_QUAL(.*?)\$TEXT_QUAL[\$FIELD_SEP\n]/xmsgc;
Fails to work as \$ is a literal $ followed by the name.


$foo =~ /\G\\$TEXT_QUAL(.*?)\\$TEXT_QUAL[\\$FIELD_SEP\n]/xmsgc;
Also Fails to work as \\ is is a literal \ The only way I've found is


$LIT_TEXT_QUAL = qq{\\$TEXT_QUAL}; $LIT_FIELD_SEP = qq{\\$FIELD_SEP}; $foo =~ /\G$LIT_TEXT_QUAL(.*?)$LIT_TEXT_QUAL[$LIT_FIELD_SEP\n]/xmsgc;


I do have reasons for using all those flags as this thread continues, however with the intent to get discrete answers to smaller problems I'm hoping to reduce the amount of new information my brain will have to process.

Basically this post is looking for a way to use any variable in a regex that may or may not contain metachacters. Edit:: OK yeah missed the boat on this one, answer is just quotemeta function, from CB thanx guys!