如何替换 perl 正则表达式中的字符串
有没有办法替换正则表达式内部的字符?
像这样:
find x | xargs perl -pi -e 's/(as dasd asd)/replace(" ","",$1)/'
来自OP的评论
code find x | xargs perl -pi -e 's/work_search=1\/ttype=2\/tag=(.*?)">(.*?)<\/a>/work\/\L$1\E\" rel=\"follow\">$2<\/a>/g'
在这种情况下,我希望 $1 的空格被 _ 替换
Is there a way to replace characters from inside the regex?
like so:
find x | xargs perl -pi -e 's/(as dasd asd)/replace(" ","",$1)/'
From OP's comment
code find x | xargs perl -pi -e 's/work_search=1\/ttype=2\/tag=(.*?)">(.*?)<\/a>/work\/\L$1\E\" rel=\"follow\">$2<\/a>/g'
in this case i want $1's spaces be replaced with _
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用嵌套替换:
请注意,
/r
修饰符需要 perl v5.14。对于早期版本,请使用:另请注意,您需要为内部替换使用不同的分隔符。如您所见,我使用了
#
。You can use a nested substitution:
Note that the
/r
modifier requires perl v5.14. For earlier versions, use:Note also that you need to use a different delimiter for the inner substitution. I used
#
, as you can see.据我了解,您想删除空格。正确吗?
你可以这样做:
As far as I understand, you want to remove the spaces. Is it correct?
You can do: