简体   繁体   中英

PhpStorm regular expression search and replace it

I use PhpStorm, this is I want to search and modify content.

<img src="/images/test1.png" class="bar" />
<img src="/images/test2.jpg" id="test" />
<div id="content">
    <img src="/assets/images/test3.png" />
</div>

I want add a helper into the src path. After modify

<img src="<?php helper_src('/images/test1.png'); ?>" class="bar" />
<img src="<?php helper_src('/images/test2.jpg'); ?>" id="test" />
<div id="content">
    <img src="<?php helper_src('/assets/images/test3.png'); ?>" />
</div>

I used the regular expression to find it <img src=(\\'|\\")\\/.*\\.(jpg|png) , how can I use Replace in Path to replace all my search result? Thanks.

If you use the following (slightly modified) regular expression:

<img src=(?:\'|\")(?<path>\/.*\.(?:jpg|png))(?:\'|\")

you can use the below "replace" value:

<img src="<?php helper_src('$1'); ?>

It contains a template that you described, and $1 puts the first matched group (it is called path ) into it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM