How to do a regular expression find replace in anki?












0















I need to do a find and replace in all cards using the following settings:



As an example I want to find:



<span style="color: rgb(255, 255, 255)">Word</span>


and change it to



Word


In other words I want to strip those text around Word.



but the problem is I have other words too.like:



<span style="color: rgb(255, 255, 255)">One</span>
<span style="color: rgb(255, 255, 255)">Two</span>
<span style="color: rgb(255, 255, 255)">Three</span>


to



One
Two
Three


I want to change them all to the word between those tags.
How can I use the search and replace of the Anki to achieve that result by providing a regular expression?
What is the correct regular expression to achieve that result?



enter image description here










share|improve this question























  • What have you tried? I have read that Anki uses the Python flavor of regex, so it should be pretty straightforward. There's even an example in the online Anki manual that I found that is pretty close to what you want. Took less than a minute to find.

    – Ron Rosenfeld
    May 20 '18 at 20:22













  • Please just provide a sample that works

    – acman123
    May 21 '18 at 9:33
















0















I need to do a find and replace in all cards using the following settings:



As an example I want to find:



<span style="color: rgb(255, 255, 255)">Word</span>


and change it to



Word


In other words I want to strip those text around Word.



but the problem is I have other words too.like:



<span style="color: rgb(255, 255, 255)">One</span>
<span style="color: rgb(255, 255, 255)">Two</span>
<span style="color: rgb(255, 255, 255)">Three</span>


to



One
Two
Three


I want to change them all to the word between those tags.
How can I use the search and replace of the Anki to achieve that result by providing a regular expression?
What is the correct regular expression to achieve that result?



enter image description here










share|improve this question























  • What have you tried? I have read that Anki uses the Python flavor of regex, so it should be pretty straightforward. There's even an example in the online Anki manual that I found that is pretty close to what you want. Took less than a minute to find.

    – Ron Rosenfeld
    May 20 '18 at 20:22













  • Please just provide a sample that works

    – acman123
    May 21 '18 at 9:33














0












0








0








I need to do a find and replace in all cards using the following settings:



As an example I want to find:



<span style="color: rgb(255, 255, 255)">Word</span>


and change it to



Word


In other words I want to strip those text around Word.



but the problem is I have other words too.like:



<span style="color: rgb(255, 255, 255)">One</span>
<span style="color: rgb(255, 255, 255)">Two</span>
<span style="color: rgb(255, 255, 255)">Three</span>


to



One
Two
Three


I want to change them all to the word between those tags.
How can I use the search and replace of the Anki to achieve that result by providing a regular expression?
What is the correct regular expression to achieve that result?



enter image description here










share|improve this question














I need to do a find and replace in all cards using the following settings:



As an example I want to find:



<span style="color: rgb(255, 255, 255)">Word</span>


and change it to



Word


In other words I want to strip those text around Word.



but the problem is I have other words too.like:



<span style="color: rgb(255, 255, 255)">One</span>
<span style="color: rgb(255, 255, 255)">Two</span>
<span style="color: rgb(255, 255, 255)">Three</span>


to



One
Two
Three


I want to change them all to the word between those tags.
How can I use the search and replace of the Anki to achieve that result by providing a regular expression?
What is the correct regular expression to achieve that result?



enter image description here







regex anki






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 20 '18 at 20:11









acman123acman123

120315




120315













  • What have you tried? I have read that Anki uses the Python flavor of regex, so it should be pretty straightforward. There's even an example in the online Anki manual that I found that is pretty close to what you want. Took less than a minute to find.

    – Ron Rosenfeld
    May 20 '18 at 20:22













  • Please just provide a sample that works

    – acman123
    May 21 '18 at 9:33



















  • What have you tried? I have read that Anki uses the Python flavor of regex, so it should be pretty straightforward. There's even an example in the online Anki manual that I found that is pretty close to what you want. Took less than a minute to find.

    – Ron Rosenfeld
    May 20 '18 at 20:22













  • Please just provide a sample that works

    – acman123
    May 21 '18 at 9:33

















What have you tried? I have read that Anki uses the Python flavor of regex, so it should be pretty straightforward. There's even an example in the online Anki manual that I found that is pretty close to what you want. Took less than a minute to find.

– Ron Rosenfeld
May 20 '18 at 20:22







What have you tried? I have read that Anki uses the Python flavor of regex, so it should be pretty straightforward. There's even an example in the online Anki manual that I found that is pretty close to what you want. Took less than a minute to find.

– Ron Rosenfeld
May 20 '18 at 20:22















Please just provide a sample that works

– acman123
May 21 '18 at 9:33





Please just provide a sample that works

– acman123
May 21 '18 at 9:33










2 Answers
2






active

oldest

votes


















0














The answer seems easy to provide but when a valid regex is applied in the ‘Find and Replace’ it simply does not work.

The documentation https://apps.ankiweb.net/docs/manual.html#find-and-replace is not helpful at all and is even misleading as it shows an example which does not work when applied.

I can only assume that it was working in some of the previous versions but was unintentionally broken.


Let’s look at couple of trials with the ‘Find and Replace’ window. I am using the following settings.
enter image description here

Observation 1

Input: <

Find: <

Replace With:

Output: <


Summary: Nothing happened. The pattern is valid but it did not work as expected.


Observation 2

Input: <

Find: ^.

Replace With:

Output: lt;


Summary: lt; reminds html entity &lt; Now we know that the regex engine is working but apparently the characters are stored differently than they look.



Anki stores collections in collection.anki2 file which is an sqlite database file. Let’s open it in DB Browser for SQLite and find the record with:
<span style="color: rgb(255, 255, 255)">One</span>
<span style="color: rgb(255, 255, 255)">Two</span>
<span style="color: rgb(255, 255, 255)">Three</span>

enter image description here



Column sfld:
<span style="color: rgb(255, 255, 255)">One<span><span style="color: rgb(255, 255, 255)">Two<span><span style="color: rgb(255, 255, 255)">Three<span>


Column flds:
<div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div>



Apparently regex works on the flds column.


Let’s try this regex:
enter image description here


Before change:
enter image description here


After change:
enter image description here


The pattern itself can be shortened but here I mainly focused on how to make it work at all.






share|improve this answer
























  • Could you please paste those regex you used as copyable text here?

    – acman123
    May 23 '18 at 0:36











  • Any of those should work: (1) &lt;span style="color: rgb(255, 255, 255)"&gt;(.*?)&lt;/span&gt; (2) &lt;span.*?&gt;(.*?)&lt;/span&gt; (3) (?<=<div>)&lt;span.*?&gt;(.*?)&lt;/span&gt;(?=</div>) Remeber to put 1 in Replace With.

    – wlod
    May 23 '18 at 8:00





















0














I thought I would just chime in to say that @wlod's answer is correct.



You can create a capture group by surrounding any matching regex pattern you would like to keep during the replacement by surrounding it with parentheses and using the convention <digit> ordered by the number of (captured) groups you specified.



This killed me too before I learned of it because in many regex implementations, the $ is used to denote a capture group, but in Anki, the is used.





Example #1



You have various animal sentences in a field on your Anki notes.
You want to keep the animal and normalize the sentences for all of them.



# Card 1
Your dog is friendly.

# Card 2
That cat is evil.

# Card 3
My fish is dead.


Find:



.*(dog|cat|fish).*


Replace:



I love my 1.


Result:



# Card 1
I love my dog.

# Card 2
I love my cat.

# Card 3
I love my fish.




Example #2



Now let's say you also wanted to keep their describing adjectives. You will need two capture groups. One for the animal and one for the adjective.



You could do this.



# Card 1
Your dog is friendly.

# Card 2
That cat is evil.

# Card 3
My fish is dead.


Find:



.*(dog|cat|fish) is (.+).


Replace:



The 2 1


Result:



# Card 1
The friendly dog

# Card 2
The evil cat

# Card 3
The dead fish


I hope this helps clarify things.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1324469%2fhow-to-do-a-regular-expression-find-replace-in-anki%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The answer seems easy to provide but when a valid regex is applied in the ‘Find and Replace’ it simply does not work.

    The documentation https://apps.ankiweb.net/docs/manual.html#find-and-replace is not helpful at all and is even misleading as it shows an example which does not work when applied.

    I can only assume that it was working in some of the previous versions but was unintentionally broken.


    Let’s look at couple of trials with the ‘Find and Replace’ window. I am using the following settings.
    enter image description here

    Observation 1

    Input: <

    Find: <

    Replace With:

    Output: <


    Summary: Nothing happened. The pattern is valid but it did not work as expected.


    Observation 2

    Input: <

    Find: ^.

    Replace With:

    Output: lt;


    Summary: lt; reminds html entity &lt; Now we know that the regex engine is working but apparently the characters are stored differently than they look.



    Anki stores collections in collection.anki2 file which is an sqlite database file. Let’s open it in DB Browser for SQLite and find the record with:
    <span style="color: rgb(255, 255, 255)">One</span>
    <span style="color: rgb(255, 255, 255)">Two</span>
    <span style="color: rgb(255, 255, 255)">Three</span>

    enter image description here



    Column sfld:
    <span style="color: rgb(255, 255, 255)">One<span><span style="color: rgb(255, 255, 255)">Two<span><span style="color: rgb(255, 255, 255)">Three<span>


    Column flds:
    <div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div>



    Apparently regex works on the flds column.


    Let’s try this regex:
    enter image description here


    Before change:
    enter image description here


    After change:
    enter image description here


    The pattern itself can be shortened but here I mainly focused on how to make it work at all.






    share|improve this answer
























    • Could you please paste those regex you used as copyable text here?

      – acman123
      May 23 '18 at 0:36











    • Any of those should work: (1) &lt;span style="color: rgb(255, 255, 255)"&gt;(.*?)&lt;/span&gt; (2) &lt;span.*?&gt;(.*?)&lt;/span&gt; (3) (?<=<div>)&lt;span.*?&gt;(.*?)&lt;/span&gt;(?=</div>) Remeber to put 1 in Replace With.

      – wlod
      May 23 '18 at 8:00


















    0














    The answer seems easy to provide but when a valid regex is applied in the ‘Find and Replace’ it simply does not work.

    The documentation https://apps.ankiweb.net/docs/manual.html#find-and-replace is not helpful at all and is even misleading as it shows an example which does not work when applied.

    I can only assume that it was working in some of the previous versions but was unintentionally broken.


    Let’s look at couple of trials with the ‘Find and Replace’ window. I am using the following settings.
    enter image description here

    Observation 1

    Input: <

    Find: <

    Replace With:

    Output: <


    Summary: Nothing happened. The pattern is valid but it did not work as expected.


    Observation 2

    Input: <

    Find: ^.

    Replace With:

    Output: lt;


    Summary: lt; reminds html entity &lt; Now we know that the regex engine is working but apparently the characters are stored differently than they look.



    Anki stores collections in collection.anki2 file which is an sqlite database file. Let’s open it in DB Browser for SQLite and find the record with:
    <span style="color: rgb(255, 255, 255)">One</span>
    <span style="color: rgb(255, 255, 255)">Two</span>
    <span style="color: rgb(255, 255, 255)">Three</span>

    enter image description here



    Column sfld:
    <span style="color: rgb(255, 255, 255)">One<span><span style="color: rgb(255, 255, 255)">Two<span><span style="color: rgb(255, 255, 255)">Three<span>


    Column flds:
    <div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div>



    Apparently regex works on the flds column.


    Let’s try this regex:
    enter image description here


    Before change:
    enter image description here


    After change:
    enter image description here


    The pattern itself can be shortened but here I mainly focused on how to make it work at all.






    share|improve this answer
























    • Could you please paste those regex you used as copyable text here?

      – acman123
      May 23 '18 at 0:36











    • Any of those should work: (1) &lt;span style="color: rgb(255, 255, 255)"&gt;(.*?)&lt;/span&gt; (2) &lt;span.*?&gt;(.*?)&lt;/span&gt; (3) (?<=<div>)&lt;span.*?&gt;(.*?)&lt;/span&gt;(?=</div>) Remeber to put 1 in Replace With.

      – wlod
      May 23 '18 at 8:00
















    0












    0








    0







    The answer seems easy to provide but when a valid regex is applied in the ‘Find and Replace’ it simply does not work.

    The documentation https://apps.ankiweb.net/docs/manual.html#find-and-replace is not helpful at all and is even misleading as it shows an example which does not work when applied.

    I can only assume that it was working in some of the previous versions but was unintentionally broken.


    Let’s look at couple of trials with the ‘Find and Replace’ window. I am using the following settings.
    enter image description here

    Observation 1

    Input: <

    Find: <

    Replace With:

    Output: <


    Summary: Nothing happened. The pattern is valid but it did not work as expected.


    Observation 2

    Input: <

    Find: ^.

    Replace With:

    Output: lt;


    Summary: lt; reminds html entity &lt; Now we know that the regex engine is working but apparently the characters are stored differently than they look.



    Anki stores collections in collection.anki2 file which is an sqlite database file. Let’s open it in DB Browser for SQLite and find the record with:
    <span style="color: rgb(255, 255, 255)">One</span>
    <span style="color: rgb(255, 255, 255)">Two</span>
    <span style="color: rgb(255, 255, 255)">Three</span>

    enter image description here



    Column sfld:
    <span style="color: rgb(255, 255, 255)">One<span><span style="color: rgb(255, 255, 255)">Two<span><span style="color: rgb(255, 255, 255)">Three<span>


    Column flds:
    <div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div>



    Apparently regex works on the flds column.


    Let’s try this regex:
    enter image description here


    Before change:
    enter image description here


    After change:
    enter image description here


    The pattern itself can be shortened but here I mainly focused on how to make it work at all.






    share|improve this answer













    The answer seems easy to provide but when a valid regex is applied in the ‘Find and Replace’ it simply does not work.

    The documentation https://apps.ankiweb.net/docs/manual.html#find-and-replace is not helpful at all and is even misleading as it shows an example which does not work when applied.

    I can only assume that it was working in some of the previous versions but was unintentionally broken.


    Let’s look at couple of trials with the ‘Find and Replace’ window. I am using the following settings.
    enter image description here

    Observation 1

    Input: <

    Find: <

    Replace With:

    Output: <


    Summary: Nothing happened. The pattern is valid but it did not work as expected.


    Observation 2

    Input: <

    Find: ^.

    Replace With:

    Output: lt;


    Summary: lt; reminds html entity &lt; Now we know that the regex engine is working but apparently the characters are stored differently than they look.



    Anki stores collections in collection.anki2 file which is an sqlite database file. Let’s open it in DB Browser for SQLite and find the record with:
    <span style="color: rgb(255, 255, 255)">One</span>
    <span style="color: rgb(255, 255, 255)">Two</span>
    <span style="color: rgb(255, 255, 255)">Three</span>

    enter image description here



    Column sfld:
    <span style="color: rgb(255, 255, 255)">One<span><span style="color: rgb(255, 255, 255)">Two<span><span style="color: rgb(255, 255, 255)">Three<span>


    Column flds:
    <div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;One&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Two&lt;span&gt;</div><div>&lt;span style="color: rgb(255, 255, 255)"&gt;Three&lt;span&gt;</div>



    Apparently regex works on the flds column.


    Let’s try this regex:
    enter image description here


    Before change:
    enter image description here


    After change:
    enter image description here


    The pattern itself can be shortened but here I mainly focused on how to make it work at all.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered May 22 '18 at 10:56









    wlodwlod

    42126




    42126













    • Could you please paste those regex you used as copyable text here?

      – acman123
      May 23 '18 at 0:36











    • Any of those should work: (1) &lt;span style="color: rgb(255, 255, 255)"&gt;(.*?)&lt;/span&gt; (2) &lt;span.*?&gt;(.*?)&lt;/span&gt; (3) (?<=<div>)&lt;span.*?&gt;(.*?)&lt;/span&gt;(?=</div>) Remeber to put 1 in Replace With.

      – wlod
      May 23 '18 at 8:00





















    • Could you please paste those regex you used as copyable text here?

      – acman123
      May 23 '18 at 0:36











    • Any of those should work: (1) &lt;span style="color: rgb(255, 255, 255)"&gt;(.*?)&lt;/span&gt; (2) &lt;span.*?&gt;(.*?)&lt;/span&gt; (3) (?<=<div>)&lt;span.*?&gt;(.*?)&lt;/span&gt;(?=</div>) Remeber to put 1 in Replace With.

      – wlod
      May 23 '18 at 8:00



















    Could you please paste those regex you used as copyable text here?

    – acman123
    May 23 '18 at 0:36





    Could you please paste those regex you used as copyable text here?

    – acman123
    May 23 '18 at 0:36













    Any of those should work: (1) &lt;span style="color: rgb(255, 255, 255)"&gt;(.*?)&lt;/span&gt; (2) &lt;span.*?&gt;(.*?)&lt;/span&gt; (3) (?<=<div>)&lt;span.*?&gt;(.*?)&lt;/span&gt;(?=</div>) Remeber to put 1 in Replace With.

    – wlod
    May 23 '18 at 8:00







    Any of those should work: (1) &lt;span style="color: rgb(255, 255, 255)"&gt;(.*?)&lt;/span&gt; (2) &lt;span.*?&gt;(.*?)&lt;/span&gt; (3) (?<=<div>)&lt;span.*?&gt;(.*?)&lt;/span&gt;(?=</div>) Remeber to put 1 in Replace With.

    – wlod
    May 23 '18 at 8:00















    0














    I thought I would just chime in to say that @wlod's answer is correct.



    You can create a capture group by surrounding any matching regex pattern you would like to keep during the replacement by surrounding it with parentheses and using the convention <digit> ordered by the number of (captured) groups you specified.



    This killed me too before I learned of it because in many regex implementations, the $ is used to denote a capture group, but in Anki, the is used.





    Example #1



    You have various animal sentences in a field on your Anki notes.
    You want to keep the animal and normalize the sentences for all of them.



    # Card 1
    Your dog is friendly.

    # Card 2
    That cat is evil.

    # Card 3
    My fish is dead.


    Find:



    .*(dog|cat|fish).*


    Replace:



    I love my 1.


    Result:



    # Card 1
    I love my dog.

    # Card 2
    I love my cat.

    # Card 3
    I love my fish.




    Example #2



    Now let's say you also wanted to keep their describing adjectives. You will need two capture groups. One for the animal and one for the adjective.



    You could do this.



    # Card 1
    Your dog is friendly.

    # Card 2
    That cat is evil.

    # Card 3
    My fish is dead.


    Find:



    .*(dog|cat|fish) is (.+).


    Replace:



    The 2 1


    Result:



    # Card 1
    The friendly dog

    # Card 2
    The evil cat

    # Card 3
    The dead fish


    I hope this helps clarify things.






    share|improve this answer




























      0














      I thought I would just chime in to say that @wlod's answer is correct.



      You can create a capture group by surrounding any matching regex pattern you would like to keep during the replacement by surrounding it with parentheses and using the convention <digit> ordered by the number of (captured) groups you specified.



      This killed me too before I learned of it because in many regex implementations, the $ is used to denote a capture group, but in Anki, the is used.





      Example #1



      You have various animal sentences in a field on your Anki notes.
      You want to keep the animal and normalize the sentences for all of them.



      # Card 1
      Your dog is friendly.

      # Card 2
      That cat is evil.

      # Card 3
      My fish is dead.


      Find:



      .*(dog|cat|fish).*


      Replace:



      I love my 1.


      Result:



      # Card 1
      I love my dog.

      # Card 2
      I love my cat.

      # Card 3
      I love my fish.




      Example #2



      Now let's say you also wanted to keep their describing adjectives. You will need two capture groups. One for the animal and one for the adjective.



      You could do this.



      # Card 1
      Your dog is friendly.

      # Card 2
      That cat is evil.

      # Card 3
      My fish is dead.


      Find:



      .*(dog|cat|fish) is (.+).


      Replace:



      The 2 1


      Result:



      # Card 1
      The friendly dog

      # Card 2
      The evil cat

      # Card 3
      The dead fish


      I hope this helps clarify things.






      share|improve this answer


























        0












        0








        0







        I thought I would just chime in to say that @wlod's answer is correct.



        You can create a capture group by surrounding any matching regex pattern you would like to keep during the replacement by surrounding it with parentheses and using the convention <digit> ordered by the number of (captured) groups you specified.



        This killed me too before I learned of it because in many regex implementations, the $ is used to denote a capture group, but in Anki, the is used.





        Example #1



        You have various animal sentences in a field on your Anki notes.
        You want to keep the animal and normalize the sentences for all of them.



        # Card 1
        Your dog is friendly.

        # Card 2
        That cat is evil.

        # Card 3
        My fish is dead.


        Find:



        .*(dog|cat|fish).*


        Replace:



        I love my 1.


        Result:



        # Card 1
        I love my dog.

        # Card 2
        I love my cat.

        # Card 3
        I love my fish.




        Example #2



        Now let's say you also wanted to keep their describing adjectives. You will need two capture groups. One for the animal and one for the adjective.



        You could do this.



        # Card 1
        Your dog is friendly.

        # Card 2
        That cat is evil.

        # Card 3
        My fish is dead.


        Find:



        .*(dog|cat|fish) is (.+).


        Replace:



        The 2 1


        Result:



        # Card 1
        The friendly dog

        # Card 2
        The evil cat

        # Card 3
        The dead fish


        I hope this helps clarify things.






        share|improve this answer













        I thought I would just chime in to say that @wlod's answer is correct.



        You can create a capture group by surrounding any matching regex pattern you would like to keep during the replacement by surrounding it with parentheses and using the convention <digit> ordered by the number of (captured) groups you specified.



        This killed me too before I learned of it because in many regex implementations, the $ is used to denote a capture group, but in Anki, the is used.





        Example #1



        You have various animal sentences in a field on your Anki notes.
        You want to keep the animal and normalize the sentences for all of them.



        # Card 1
        Your dog is friendly.

        # Card 2
        That cat is evil.

        # Card 3
        My fish is dead.


        Find:



        .*(dog|cat|fish).*


        Replace:



        I love my 1.


        Result:



        # Card 1
        I love my dog.

        # Card 2
        I love my cat.

        # Card 3
        I love my fish.




        Example #2



        Now let's say you also wanted to keep their describing adjectives. You will need two capture groups. One for the animal and one for the adjective.



        You could do this.



        # Card 1
        Your dog is friendly.

        # Card 2
        That cat is evil.

        # Card 3
        My fish is dead.


        Find:



        .*(dog|cat|fish) is (.+).


        Replace:



        The 2 1


        Result:



        # Card 1
        The friendly dog

        # Card 2
        The evil cat

        # Card 3
        The dead fish


        I hope this helps clarify things.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 30 '18 at 5:17









        JesseJesse

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1324469%2fhow-to-do-a-regular-expression-find-replace-in-anki%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

             ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕