Multiline search and replace

Aleksej's Avatar

Aleksej

11 Jun, 2020 07:48 PM

I am trying to replace (in Anki 2.1.22) <a [^>]*href="([^"]+)"[^>]*?>(.*?)</a>
with [<span class="linklike">\2</span>](\1)

But it doesn't work in this case. Apparently it's because of the line break:

the <a href="/archives/polnotes.html">daily
political notes</a>.

Is there a way?

  1. Support Staff 1 Posted by Damien Elmes on 12 Jun, 2020 06:04 AM

    Damien Elmes's Avatar

    In the latest alpha you can start the search with (?s) to search across newlines - maybe it'll work in older versions too.

  2. 2 Posted by Aleksej on 12 Jun, 2020 07:39 AM

    Aleksej's Avatar

    Thank you, it works.

  3. 3 Posted by Aleksej on 13 Jun, 2020 11:53 PM

    Aleksej's Avatar

    Hm, now pictures from the links are being lost.

  4. 4 Posted by Aleksej on 16 Jun, 2020 10:15 PM

    Aleksej's Avatar

    It also loses link text.

    At least this one does not:

    (s?)<a [^>]*href="(?P<hrefattr>[^"]+)"[^>]*?>(?P<insidea>.*?)</a>

    [<span class="linklike">\g<insidea></span>](\g<hrefattr>)

Comments are closed, but you can start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac