Find and replace notepad++ with wildcards

32,481

Find and Replace multiline string of text between tags

Solution #1

Use the following regex in Find what: \[anchor=ad1\](.*?)\[anchor=ad1end\],
Replace with: [anchor=ad1]replace[anchor=ad1end]
and select Regular expression and [x] . matches newline

Notepad++ find and replace regex example

Sample data for testing:

[anchor=ad1]some multiline string of text
   that should be replaced[anchor=ad1end]
[anchor=ad1][img]http://i.imgur.com/some_image.png[/img]
   another one multiline string of text
   that should be replaced[anchor=ad1end]
...

Solution #2

A little more advanced solution. This requires Notepad++ v6.0 or above.

Find what: (?<=\[anchor=ad1\]).*?(?=\[anchor=ad1end\])
Replace with: replace
select Regular expression and [x] . matches newline
Important Note: Replace button is NOT working in Notepad++ v6.1.6, but the Replace All works just fine.

enter image description here

Share:
32,481

Related videos on Youtube

Adam
Author by

Adam

Updated on September 18, 2022

Comments

  • Adam
    Adam over 1 year

    I've read about 15 tutorials on regular expression however I'm clearly not getting as I've been unable to tailor it to my problem.

    I have one set of code which would be found in many different documents. There may be variants of these with different content between the two anchor tags, but here is one variant (the others are all of similar form).

    [anchor=ad1][img]http://i.imgur.com/48rwaraw.png[/img] 
                                     [URL=http://goo.gl/Ii3WNz][img]http://i.imgur.com/rBbf7nM.png[/img][/URL]
                                                     [size=7pt]Advertised sites are not endorsed and may be unsafe, untrustworthy, or illegal in your jurisdiction. [url=http://goo.gl/aw52j52]Advertise here.[/url][/size]
    [img]http://i.imgur.com/48rwaraw.png[/img][anchor=ad1end]
    

    I want to be able to replace everything between the anchor tags, ie where my * is here:

    [anchor=ad1]*[anchor=ad1end]
    

    The replacement would include similar characters to the original, if that makes a difference. I just can't seem to get the regular expression stuff to find the correct string, nevermind replace it with another. Thanks for the help.

    Edit: Using ToolBucket to use multiline

    • DavidPostill
      DavidPostill about 9 years
    • Adam
      Adam about 9 years
      As I said, I've read about 15 of these and it doesn't help me. When I follow what appear to be the rules, I get unexpected results which aren't close.
    • Dmytro Dzyubak
      Dmytro Dzyubak about 9 years
      Have a look at this solution: superuser.com/a/482293/300393 It's somewhat related, but does not solve Your problem completely.
    • barlop
      barlop over 7 years
      You should have stated in your question, what you'd tried, and what was confusing you.
  • Adam
    Adam about 9 years
    This does not give me the expected result, instead it finds all results after the opening [ character, and goes on to find other varients (ad2 etc) all the way until the character before the final ] at anchor=ad3.
  • Adam
    Adam about 9 years
    Perfect, thanks. I was really close to this, I think I just had one character different yet it totally ruined it.
  • barlop
    barlop over 7 years
    @Adam what did you have?