-3

I have more html links such as:

<a href="https://liber5fg.files.wordpress.com/2011/02/picture-183.jpg"><img loading="lazy" blah blah" /></a>
<a href="https://binterest68.wordpress.com/picture-183.jpg"><img loading="lazy" blah blah" /></a>
<a href="https://stevepeter.gono.com/picture-183.jpg"><img loading="lazy" blah blah" /></a>
<a href="https://sonarhut.com/bing0235644545.jpg"><img loading="lazy" blah blah" /></a>

I must use a regex to select/delete all links except the 3'th one with <a href="https://stevepeter.gono.com...

So, after find and replace, the output should be:

<a href="https://stevepeter.gono.com/picture-183.jpg"><img loading="lazy" blah blah" /></a>

I try this regex, but doesn't work too good:

FIND: (?s)<a href="https://+\K(?!stevepeter).+</a>(?-s)

7
  • What have you tried already?
    – harrymc
    Apr 3, 2022 at 16:22
  • stackoverflow.com/a/1732454
    – Gantendo
    Apr 3, 2022 at 17:11
  • Have you tried using an XML parser instead?
    – Gantendo
    Apr 3, 2022 at 17:19
  • 1
    @Gantendo From my experience, OP does not do parsers. They ask about Notepad++ regex here. Apr 3, 2022 at 17:40
  • I edit the post. I try this regex, but doesn't work too good: FIND: (?s)<a href="https://+\K(?!stevepeter).+</a>(?-s)
    – Just Me
    Apr 3, 2022 at 17:41

2 Answers 2

0

Use the following:

  • Ctrl+H
  • Find what: (?s)<a href="https://(?!stevepeter)(?-s).+</a>
  • Replace with: LEAVE EMPTY
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all
0

another solution is to use this 2 generic formulas:

  • Find what: (?s)BSR(FR)(?-s).+ESR

    or

  • Find what: BSR(FR).+(?s:(?=.*(ESR)))

  • BSR Begin Region Start

  • ESR End Search Region

  • FR Find Regex (here you put the formula for exception, staring with ?! )

In your case generic formula can be implement like this:

  • Ctrl+H
  • Find what: <a href="https://(?!stevepeter).+(?s:(?=.*(</a>)))
  • Replace with: EMPTY
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .