L
L
lexxand2021-06-05 18:50:22
Regular Expressions
lexxand, 2021-06-05 18:50:22

How to apply a regular expression in a string?

Yesterday I was prompted with my question how to "wrap" the image link with other tags.
The original text is like this

<img src=""555.jpg"" />
<img src=""666.jpg"" />
<img src=""777.jpg"" />

Should have been replaced with this
<a href="555.jpg"><img src=""555.jpg"" /></a>
<a href="666.jpg"><img src=""666.jpg"" /></a>
<a href="777.jpg"><img src=""777.jpg"" /></a>

This is solved by searching and replacing in Notepad++ using regular expressions, thanks for the solution Dmitry
<img src=\"(.*)\" \/>
<a href="\1"><img src="\1" /></a>

I did not take into account one nuance, in my text, there are a lot of these links, in one line, in a row. For example like this:
<p><img src=""555.jpg"" /></p><p><img src=""666.jpg"" /></p><p><img src=""777.jpg"" /></p>

And then the solution that Dmitry suggested to me does not work.
How to tweak the regular expression so that it searches and replaces values, even in a line with other similar values?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-06-05
@lexxand

<img src=\"(.*?)\" \/>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question