PhpStorm regular expression search and replace it

lighter

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.

Yury Fedorov

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regular expression: Search/replace

From Dev

regular expression search replace in Sublime

From Dev

Search And Replace With Regular Expression webuilder

From Java

Regular expression search replace in Sublime Text 2

From Dev

Dreamweaver help needed with regular expression search and replace

From Dev

Vim - incremental numbering via regular expression search and replace

From Dev

Multiple search and replace within a string through regular expression in SAS

From Dev

Search and replace in only certain tags and attributes in XML file by a regular expression

From Java

Regular expression replace with self

From Dev

XSLT + regular expression replace

From Dev

Regular expression failed replace

From Dev

Regular expression to replace text

From Dev

Regular expression to replace a string

From Dev

Regular expression replace [*

From Dev

Find and replace regular expression

From Dev

Regular Expression to replace AND

From Dev

regular expression to replace div

From Java

Regular expression to search for Gadaffi

From Dev

Pip regular expression search

From Dev

search for regular expression with the symbol '

From Dev

Regular Expression to search substring

From Dev

Search link with regular expression

From Dev

Regular Expression for the search string

From Dev

Ruby regular expression search

From Dev

vscode Regular expression search?

From Dev

Dynamic replace in regular expression scope

From Dev

How to replace Kate regular expression

From Dev

NotePad++ Regular Expression and Replace

From Dev

replace regular expression via vimscript