Home > database >  Replace a string using Notepad and regex
Replace a string using Notepad and regex

Time:02-21

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

CodePudding user response:

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.

CodePudding user response:

Try

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

CodePudding user response:

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" />
  • Related