为什么我会有语法错误?
% perl -ne 'if (/https://([-.0-9A-Za-z]+\.[-0-9A-Za-z]+)/) { print $1 ; }'
Bareword found where operator expected at -e line 1, near "9A"
(Missing operator before A?)
Bareword found where operator expected at -e line 1, near "9A"
(Missing operator before A?)
syntax error at -e line 1, near "9A"
syntax error at -e line 1, near ";}"
Execution of -e aborted due to compilation errors.发布于 2013-11-27 05:13:05
如果regex包含斜杠,请使用不同的字符和显式m运算符:
perl -ne 'if (m%https://([-.0-9A-Za-z]+\.[-0-9A-Za-z]+)%) { print $1 ; }'或者:
perl -ne 'print $1 if m{https://([-.0-9A-Za-z]+\.[-0-9A-Za-z]+)}'https://stackoverflow.com/questions/20234354
复制相似问题