afraid-scarlet•2y ago
Cannot get regex to work in Anki addon
First obvious question:
Is the field name the field passsed by the Migaku browser extension, or the field that that field is mapped to in Anki? Ie. should I call it eg. Sentence (from Migaku) or 'MyFieldName'?
I am trying to modify the stuff internal to curly braces. For now, testing with just deleting them, I have no luck. Regex is
\{[^\}]+\}
, which should work, as far as I can tell. Maybe something to do with the escaping slashes and how the addon is interpreting them?3 Replies
fair-rose•2y ago
You should select the field name as it shows up in the Card Browser. Can you give an example of what you want to change?
afraid-scarletOP•2y ago
Sure. For now I just want to get regexes working at all, I am fairly used to writing regex, so I just want to delete the text between curly braces as a test. (I'll worry about changing it later.)
Field name: Expression
Regex:
\{[^\}]+\}
This should match the {...} below:
米連邦準備理事会(FRB)の高官らは米経済の{...}
->
米連邦準備理事会(FRB)の高官らは米経済の
The migaku addon regularly makes these when creating cards with subtitles that have punctuation. For example, pulling a random line from a show:
ちゃんと[;h] 夏[なつ;o] で も 腹巻[はらま;n2]き し[,する;h]て 寝[ね,ねる;h]ねば わがねよ[,わがねる]{!}
I have noticed one other thing just now: if I edit the regex fields and immediately close the settings window it closes as expected. If I edit and then click somewhere else in the settings pane, anki crashes. RAM use does go up a bit before that happens, but not by a huge amount.
I have tested this with both my own card types and the Migaku card types.
Not 100% on how to get good debugging info from anki. Maybe it is because I have a large collection as well, I might try on a profile with less cards.
No dice with that.
Going to do some due diligence, though:
I am on Anki beta versions, I'll downgrade to the actually supported version. It's never usually an issue, but...
Also going to disable all my other addons and then test.
Will report back.fair-rose•2y ago
It adds the curly braces to escape spaces and other characters from being parsed as Migaku Syntax. The braces should be hidden by the Migaku Note Type Javascript. But anyway, your regex works fine in my version of Anki. I'm not sure why it doesn't work for you.