How do I extract abc from 'abc' using a Perl regular expression?
I tried
echo "'abc'" | perl -ne 'if(/\'(.*)\'/) {print $1}'
but it showed:
-bash: syntax error near unexpected token `('
This is not a Perl problem; this is a shell problem: you cannot include single quotes into single quotes.
You have to replace each single quote with '\''
(end of single quotes, escaped single quote, and start of single quotes):
echo "'abc'" | perl -ne 'if(/'\''(.*)'\''/) {print $1}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With