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

**URL:** <https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778>\
**Category:** Add-ons\
**Created:** [January 23, 2021, 2:02pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778 "2021-01-23T14:02:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ijgnd](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@ijgnd](https://forums.ankiweb.net/u/ijgnd)\
**Post date:** [January 23, 2021, 2:02pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/1 "2021-01-23T14:02:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Fouda4ever](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fouda4ever](https://forums.ankiweb.net/u/Fouda4ever)\
**Post date:** [July 18, 2021, 12:10am UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/2 "2021-07-18T00:10:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hengiesel](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/hengiesel/32/920_2.png) [@hengiesel](https://forums.ankiweb.net/u/hengiesel)\
**Post date:** [July 18, 2021, 12:20am UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/3 "2021-07-18T00:20:41Z")

</div>

You’re looking for [“Find and Replace…”](https://docs.ankiweb.net/browsing.html#find-and-replace), which is a built-in Anki feature, which you can access from the browser.

---

<div class="post-metadata">

**Author:** ![Fouda4ever](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fouda4ever](https://forums.ankiweb.net/u/Fouda4ever)\
**Post date:** [July 18, 2021, 12:33am UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/4 "2021-07-18T00:33:36Z")

</div>

Thanks, but how can i add many replacements

---

<div class="post-metadata">

**Author:** ![hengiesel](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/hengiesel/32/920_2.png) [@hengiesel](https://forums.ankiweb.net/u/hengiesel)\
**Post date:** [July 18, 2021, 1:08am UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/5 "2021-07-18T01:08:41Z")

</div>

You must run it multiple times.

---

<div class="post-metadata">

**Author:** ![Tomasz\_Osak](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@Tomasz\_Osak](https://forums.ankiweb.net/u/Tomasz_Osak)\
**Post date:** [November 11, 2021, 6:55pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/6 "2021-11-11T18:55:37Z")

</div>

Great!  
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.

---

<div class="post-metadata">

**Author:** ![ijgnd](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@ijgnd](https://forums.ankiweb.net/u/ijgnd)\
**Post date:** [December 18, 2021, 8:48pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/8 "2021-12-18T20:48:40Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![gustavosmen](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@gustavosmen](https://forums.ankiweb.net/u/gustavosmen)\
**Post date:** [July 13, 2022, 3:46pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/10 "2022-07-13T15:46:08Z")

</div>

@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](https://superuser.com/questions/1702617/regex-convert-the-first-lowercase-letter-of-the-starting-words-into-capital-let) but it break the add-on.

---

<div class="post-metadata">

**Author:** ![ijgnd](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@ijgnd](https://forums.ankiweb.net/u/ijgnd)\
**Post date:** [July 14, 2022, 2:07pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/11 "2022-07-14T14:07:04Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Yaser](https://avatars.discourse-cdn.com/v4/letter/y/8e7dd6/32.png) [@Yaser](https://forums.ankiweb.net/u/Yaser)\
**Post date:** [August 13, 2022, 3:55pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/12 "2022-08-13T15:55:20Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![ijgnd](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@ijgnd](https://forums.ankiweb.net/u/ijgnd)\
**Post date:** [August 16, 2022, 10:22am UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/13 "2022-08-16T10:22:24Z")

</div>

@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).

---

<div class="post-metadata">

**Author:** ![gustavosmen](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@gustavosmen](https://forums.ankiweb.net/u/gustavosmen)\
**Post date:** [October 3, 2022, 6:46pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/14 "2022-10-03T18:46:39Z")

</div>

@ijgnd Hi, the add-on breaks in the new browser’s editor. It doesn’t do the regex properly.

---

<div class="post-metadata">

**Author:** ![ijgnd](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@ijgnd](https://forums.ankiweb.net/u/ijgnd)\
**Post date:** [October 7, 2022, 7:18pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/15 "2022-10-07T19:18:35Z")

</div>

for me it works in Anki 2.1.54. can you share the regex and the expected result. Have you confirmed that your regex expression works as expected in a different tool like an online site like [regex101.com](http://regex101.com) (with the python setting)? What OS do you use. what exact anki version? does this still happen after having disabled all other add-ons and having restarted anki?

---

<div class="post-metadata">

**Author:** ![gustavosmen](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@gustavosmen](https://forums.ankiweb.net/u/gustavosmen)\
**Post date:** [October 7, 2022, 7:32pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/16 "2022-10-07T19:32:22Z")

</div>

Hi, i meant to say in the new version: 2.1.55, with the browser in vertical mode

---

<div class="post-metadata">

**Author:** ![ijgnd](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@ijgnd](https://forums.ankiweb.net/u/ijgnd)\
**Post date:** [October 8, 2022, 7:41am UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/17 "2022-10-08T07:41:09Z")

</div>

it also works in 2.1.55 in the browser with each editor orientation for me. without more info there’s nothing I can do (see my prior post).

---

<div class="post-metadata">

**Author:** ![gotaquestion](https://avatars.discourse-cdn.com/v4/letter/g/e95f7d/32.png) [@gotaquestion](https://forums.ankiweb.net/u/gotaquestion)\
**Post date:** [January 12, 2023, 2:01am UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/18 "2023-01-12T02:01:25Z")

</div>

Thanks a lot for writing the add-on! It’s extremely helpful!

Here’s what I’m wondering: In the add-on description on AnkiWeb it says that the add-on “gives you a shortcut to apply all of these substitutions/replacements on the currently active field of the editor”. However, when I press the shortcut, the config window opens. The same happens when I click the context menu entry. So the only way I found to invoke the substitutions is pressing the toolbar button.

Am I doing something wrong or is that the intended behaviour?

---

<div class="post-metadata">

**Author:** ![ijgnd](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@ijgnd](https://forums.ankiweb.net/u/ijgnd)\
**Post date:** [January 17, 2023, 1:30pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/19 "2023-01-17T13:30:40Z")

</div>

Thanks for reporting this bug. I’ll upload a fixed version when I have more time.

If you avoid shortcuts with shift it should work as expected. I never noticed this as a problem because the shortcut I use “Meta+ctrl+e” works.

---

<div class="post-metadata">

**Author:** ![gotaquestion](https://avatars.discourse-cdn.com/v4/letter/g/e95f7d/32.png) [@gotaquestion](https://forums.ankiweb.net/u/gotaquestion)\
**Post date:** [January 17, 2023, 4:38pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/20 "2023-01-17T16:38:50Z")

</div>

You’re right, when I set the shortcut to something without shift it works indeed! Thank you for the tip!

The Windows key functions as Meta key, right? Because I just tried out what happens when I set the shortcut to “Meta+Ctrl+E” as you suggested but nothing happens when I press “Windows+Ctrl+E”.

---

<div class="post-metadata">

**Author:** ![gotaquestion](https://avatars.discourse-cdn.com/v4/letter/g/e95f7d/32.png) [@gotaquestion](https://forums.ankiweb.net/u/gotaquestion)\
**Post date:** [February 21, 2023, 2:32am UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/21 "2023-02-21T02:32:05Z")

</div>

I have a suggestion and a question. 😊

My suggestion:  
Add the following text to the toooltip when the user hovers over the toolbar button:

> Hold “Shift” and click the button to open the config window for simple replacements.  
> Hold “Ctrl+Shift” and click the button to open the config window for regex replacements.

My question:  
Are the simple replacements and the regex replacements always both carried out? Or is it somehow possible to invoke one without the other?

---

<div class="post-metadata">

**Author:** ![ijgnd](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@ijgnd](https://forums.ankiweb.net/u/ijgnd)\
**Post date:** [February 23, 2023, 7:56pm UTC](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778/22 "2023-02-23T19:56:25Z")

</div>

at the moment the regular and regex are always both run. to change this you’d have to edit the source code of the add-on. I’ve added it to my todo list but at best it will take some months …

[Next page](https://forums.ankiweb.net/t/editor-batch-replace-in-one-field-also-with-regex-official-thread/6778.md?page=2)
