我是Perl的新手,我正在尝试弄清楚如何让这个东西工作。
我在这个帖子里找到了一个例子:Perl Regex - Print the matched value
下面是我正在尝试使用的示例:
perl -e '$str="the variable Xy = 3 in this case"; print $str =~ /(Xy = 3)/;'我尝试使用cmd来运行它,但是产生了这个错误:
“在-e行%1的EOF前的任何位置找不到字符串终止符”。“
当我在powershell中运行它时,没有任何反应。
我的最终目标是在命令行中设置一个变量,运行regexp find (有时还包括replace),并打印结果。这样,我就不必在每次编写regexp模式时都编写脚本。
我尝试过使用调试器,但在设置变量后执行此操作时没有任何反应:
print $str =~ /(Xy = 3)/;发布于 2013-12-22 12:03:59
在windows环境中,最好将语句放在Perl脚本中,因为大多数Perl内容都需要双引号,但是在命令行上转义最终会变得混乱。
发布于 2013-12-22 11:05:13
好的,我为powershell解决了这个问题。我不得不避开双引号。
perl -e '$str=\"the variable Xy = 3 in this case\"; print $str =~ /(Xy = 3)/;'cmd也是如此,除了我必须用双引号替换单引号之外,因为单引号不是字符串分隔符。
perl -e "$str=\"the variable Xy = 3 in this case\"; print $str =~ /(Xy = 3)/;"https://stackoverflow.com/questions/20725822
复制相似问题