How do I avoid left parsing in a Perl regex?

If I have a file containing some escaped parsers, how can I replace all instances with an irreproducible finger using Perl?

i.e. rotate this:

.... foo\(bar ....

in that

.... foo(bar ....

I tried the following but received this error message:

perl -pe "s/\\\(/\(/g" ./file
Unmatched ( in regex; marked by <-- HERE in m/\\( <-- HERE / at -e line 1.
+3
source share
3 answers

You forget that the backslash also means something to the shell. Try using single quotes instead of double quotes. (Or put your script in a file where you don't have to worry about quoting the shell.)

+11
source

G. From the command line, no less. Way too many levels of interpretation of metacharacters.

, , .

+6

cjm answer is probably the best. If you must do this on the command line, try using quotemeta () or metaquoting escape sequence (\ Q ... \ E) . This worked for me at the bash prompt:

perl -pe "s/\Q\(\E/(/g" ./file
0
source

Source: https://habr.com/ru/post/1703531/


All Articles