Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace SRC and HREF attributes using regex in PHPStorm

i am new to laravel and i just got this html template i am converting to a blade template in my application. However i would like to replace the src and href attributes of all the links and images on the page with the laravel assets function. eg.

Change

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

to

<script type="text/javascript" src="{{ asset('js/jquery.js') }}"></script>

Unfortunately there are so many of these in my template that i was wondering if there was a way to just do this with regular expressions using the replace tool in my editor.

like image 237
user3718908x100 Avatar asked Feb 20 '26 18:02

user3718908x100


1 Answers

You can do it using capturing groups.

Go Edit->Find->Replace.. , check Regex

In the first row you should enter:

<script type="text/javascript" src="(.+)"></script>

In the second row:

<script type="text/javascript" src="{{ asset('$1') }}"></script>

With images you can do it similarly.

like image 170
Stas Makarov Avatar answered Feb 24 '26 05:02

Stas Makarov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!