PyCharm. Regular expression to replace all script src attributes

I need to refactor my existing django code using a tag {% static 'path/to/file' %}

. I think it is possible to use PyCharm's "Replace in Path" function with the regex option.

So, I need to replace the script tags that now look like this:

<script type="text/javascript" src="/static/js/script.js"></script>


To look like this:

<script type="text/javascript" src="{% static 'js/script.js' %}"></script>


Here is the "Replace on the way" picarma window:

enter image description here

I think I need to pass "Text to find" something like src="([^"]+)"

, but what should I pass in "Replace with" I can't figure out.

Thanks in advance.


source to share

1 answer

A simplified version of your regex would be src="(.+?)"

. Instead, you can use the following expression to match



And replace with

src="{% static '$1' %}"




All Articles