Regex that worked on Sublime not working on Pychar

2019-02-19 19:29发布

问题:

Ok so, in Sublime Text I can use this Find/Replace regex:

find: (src|href)="(assets\/.+?)"
replace: \1="{% static '\2' %}"

To replace this

<link href="assets/css/cssfile.css">

With this:

<link href="{% static 'assets/css/cssfile.css' %}"/>

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.

回答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.



标签: regex pycharm