Editor: batch replace in one field, also with regex [Official thread]

If you have a problem with the add-on editor batch multi replace post in this thread. This way I get notified. If you make a new thread I will likely miss it.

1 Like

How about changing multiple things in one field in many notes ?

You’re looking for “Find and Replace…”, which is a built-in Anki feature, which you can access from the browser.


Thanks, but how can i add many replacements

You must run it multiple times.

It would be good to know in advance that it uses rather Python-compatible than POSIX-compatible regex, so eg. one have to use rather \1 than $1 for backreferences. And that it operates rather on content that you see in HTML editor than on content you see normally in editor while adding/editing a note. It took me a while to figure it out.

@JBrown: Thanks for reporting the error. Because of my custom config I didn’t notice that for other people my add-on had a bug. I just uploaded a new version that should fix it. Could you update your add-ons, restart Anki and try again. If you find other errors please let me know.

@ijgnd It would be possible to use your add-on to capitalize the first letter of a field?

I’ve tried using this notepad++ - Regex: Convert the first lowercase letter of the starting words into capital Letter (after .dot) - Super User but it break the add-on.

@gustavosmen: there’s probably some way but it’s too complicated for me … So I can’t help.

the relevant part of the source code is in the file editor.py of my add-on in the function batch_replacer_helper (the line html = re.sub ...)

The problem is that I edit the html source code. So the first visible character is not necessarily the first character of the html source code. So I would have to handle all special cases that could occur or work back from plain text to the html source …

I have no quick fix or code snippet for this.

1 Like

Hi man
So I posted on reddit the following : I want an add on that removes the extra spaces between words especially when copying and creating flashcards from a PDF. and one person recommended your add on but he said put
in the add on config and I tried it and it didn’t work probably because I use the code in a wrong way so could you help me ?

@Yaser: It depends on how the html source code looks like. I don’t have some snippets that work in each case. But I plan to update the remove linebreak add-on soon (once the next anki version is released which has support for an essential add-on for me).