Why is my regular expression invalid?

I want to find and replace part of a field for all the cards in a deck. I am getting an error message that my regex is invalid. I’ve tested the regex in Sublime Text and it works there. I’m not sure why it’s invalid. I tried three regexs which work in other places, but not in Anki find and replace.

A[^`]+B

A(?s).+B

A(?:.|\s)+B

Does anyone know why it’s invalid?
All I need is to replace everything from word A to word B (there may be one or more newlines between the two words). If you know of another way I can do that, please let me know.

Thank you in advance for your help.

The regexes work for me. Maybe you have some special characters in A or B like \ that need escaping? You can post the full example that causes the issue.

2 Likes

A = hans:
B = trad:

hans\:[^`]+trad\: 

hans\:(?s).+trad\: 

hans\:(?:.|\s)+trad\: 

: must not be escaped.
By the way, using the browser search provides a more detailed error:

grafik

4 Likes

Removing the backslashes solved the issue and it works now. Thank you so much!

1 Like

Do you know where I can find more info about which characters should and shouldn’t be escaped for Anki?

For escaping in Anki searches: Searching - Anki Manual
For escaping in Anki regexes: regex - Rust

4 Likes