Hello all
Regular Expressions seem to be a source of great frustration to me. Principally because I haven't used them enough.
I am wanting to take a string and do the following
1. Remove leading and ending single or double quotes.
2. Add escape '/' to all metacharacters within the string.
3. Do it all in one statement.
I am able to do it with many statements (below), but am hoping there is a much cleaner way.
$ptext =~ s/^\"//; $ptext =~ s/\"$//; $ptext =~ s/^\'//; $ptext =~ s/\'$//; $ptext =~ s/\'/\\\'/g; $ptext =~ s/\"/\\\"/g; $ptext =~ s/\{/\\\{/g; # ...
In reply to Regexp and metacharacters by Largins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |