适用于 Sublime 的正则表达式不适用于 Pycharm [英] Regex that worked on Sublime not working on Pycharm
本文介绍了适用于 Sublime 的正则表达式不适用于 Pycharm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,在 Sublime Text 中我可以使用这个查找/替换正则表达式:
Ok so, in Sublime Text I can use this Find/Replace regex:
find: (src|href)="(assets\/.+?)"
replace: \1="{% static '\2' %}"
替换这个
<link href="assets/css/cssfile.css">
有了这个:
<link href="{% static 'assets/css/cssfile.css' %}"/>
当我在 Pycharm 中使用相同的正则表达式时,它没有正确替换值..这是正则表达式问题还是 Pycharm 问题?我不确定,因为我对正则表达式有点陌生.
When I use the same regexes in Pycharm, it doesn't replace the values correctly.. is it a regex problem or a Pycharm problem? I'm not sure since I'm kind of new to regular expressions.
推荐答案
如 PyCharm 文档,在 PyCharm 中,您需要使用 $1 而不是 \1 来引用替换表达式中的组.
As described in the PyCharm documentation, in PyCharm you need to use $1 rather than \1 to refer to a group in the replacement expression.
这篇关于适用于 Sublime 的正则表达式不适用于 Pycharm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文