Ale*_*r O 5 python regex django pycharm
我需要通过使用{% static 'path/to/file' %}标记来重构现有的django代码.我认为使用正则表达式选项可以使用PyCharm功能"路径替换".
所以,我需要替换我的脚本标签,现在看起来像:
<script type="text/javascript" src="/static/js/script.js"></script>
Run Code Online (Sandbox Code Playgroud)
看起来像:
<script type="text/javascript" src="{% static 'js/script.js' %}"></script>
Run Code Online (Sandbox Code Playgroud)
这是pycharm"在路径中替换"窗口:

我想我应该传入"Text to find"之类的东西src="([^"]+)",但是我应该传递"替换为",我无法理解.
先感谢您.
kar*_*ala 11
你的正则表达式的简化版本将是src="(.+?)".相反,您可以使用以下表达式进行匹配
src="/static/(.+?)"
Run Code Online (Sandbox Code Playgroud)
并替换为
src="{% static '$1' %}"
Run Code Online (Sandbox Code Playgroud)