Torieu
Torieu

Reputation: 15

Replace a string using Notepad++ and regex

I have strings like this:

<img src="http://www.example.com/app_res/emoji/1F60A.png" /><img src="http://www.example.com/app_res/emoji/1F389.png" />
<img src="http://www.example.com/app_res/emoji/1F61E.png" /><img src="http://www.example.com/app_res/emoji/1F339.png" />

I want them to be like this:

&#x1F60A; &#x1F389;
&#x1F61E; &#x1F339;

In Notepad++, I tried this :

Find what: ^\s*<img src="http://www.example.com/app_res/emoji/(1F.*).png" />

Replace with: &#x\1;

The result is not as expected:

&#x1F60A.png" /><img src="http://www.example.com/app_res/emoji/1F389;

How to best isolate the regular expression ?

Any help is welcome ! Thank you

Upvotes: 0

Views: 229

Answers (3)

Haji Rahmatullah
Haji Rahmatullah

Reputation: 430

Try

Find:^<.*?/(1\w+).*?/(1\w+).* Replace:&#x$1; &#x$2;

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522732

You may try the following find and replace, in regex mode:

Find:    <img src=".*?/([A-Z0-9]+\.\w+"\s*/><img src=".*?/([A-Z0-9]+\.\w+"\s*/>
Replace: &#x$1; &#x$2;

Here is a working regex demo.

Upvotes: 1

Tomalak
Tomalak

Reputation: 338406

You're using the unspecific . together with the greedy star *. Don't do that here, as this tends to overshoot the target.

Be more specific.

The file name (in your case) does not contain dot's. Let's use "anything except a dot" ([^.]*) instead of "anything" (.*):

^\s*<img src="http://www.example.com/app_res/emoji/(1F[^.]*).png" />

Upvotes: 1

Related Questions