Say I have the following in perl:
my $string;
$string =~ s/ /\\ /g;
$string =~ s/'/\\'/g;
$string =~ s/`/\\`/g;
Can the above substitutions be performed with a single combined regular expression instead of 3 separate ones?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Uses a character class
[ '`]to match one of space, ‘ or ` and uses brackets()to remember the matched character.$1is then used to include the remembered character in the replacement.