-1

I have a txt file containing about 10000 lines. In every line, I have a specific character (%20) that repeats two times. I need to replace the second occurrence with another word and keep the first one. Is there any Notepad++ Regular Expression for that?

Here is my text:

My name is %20John. my friend's name is %20john too.
My name is %20paul. my friend's name is %20paul too.
.
.

I need it to be like this:

My name is %20John. my friend's name is john too.    
My name is %20paul. my friend's name is paul too.

2 Answers 2

2

You may use something like this:

^(.+?%20.+?)%20

..and replace with:

\1

..which will remove the second occurrence of %20. If you want to replace it with something else (e.g., SomeWord), you may use \1SomeWord in the "Replace With" field.

Demo.

2
  • Thanks. It worked very well, but there was something I forgot to mention. The number of (%20)s varies in each line and I have even 10 of them in some lines, and therefore this Regex does not work in those lines. There is some constant part in all lines and it is (dl=0">). I need to remove all the (%20) after this constant and replace it with space. All (%20) before this constant should not be removed. Can you help me with that? example: %20my %name %is %john dl=0"> %20my %name %is %john should change to: %20my %name %is %john dl=0"> my name is john
    – Sanila
    May 13, 2020 at 2:46
  • 1
    @Sanila This sounds like a different question so, I would say it's probably a good time to ask a new one.
    – ICloneable
    May 13, 2020 at 13:45
0

Try this code, it will do the job as expected ...

Find what: (.*?\K%){2}\d+
Replace with: nothing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.