ImperialSquid / zotero-zotts

A Zotero plugin adding text to speech (TTS) functionality to various screens
GNU Affero General Public License v3.0
86 stars 1 forks source link

[Question]: Regex question #135

Open v4u6h4n opened 6 hours ago

v4u6h4n commented 6 hours ago

Checklist

Feature or improvement you want

Can you make a discussions section available for the repo? I have some dumb questions about pronunciation and regex that I dont want clogging up the issues section of the repo.

Why should this be added?

No response

Screenshots / Drawings / Technical details

No response

ImperialSquid commented 6 hours ago

Eh, given ZoTTS isn't a huge project I don't think you're drowning out other discussions and/or at risk of being buried, other than your comment the other day, the most recent activity in the issues was a week ago lol. I'm also hesitant to split up the conversations in case someone else has the same questions you do, it's just one more place to search for not that much gain...

That said, I'm happy to answer any and all questions you have here! 😊

v4u6h4n commented 1 hour ago

Okay cool :-)

I'm just wondering what regex to use to allow, for example, the pronunciation of $100 (or any dollar amount), so that it is pronounced one hundred dollars instead of dollar one hundred.

ImperialSquid commented 20 minutes ago

No worries!

For that I think /\$([0-9\.]+)/:"\1 dollars" should work. (Just paste it directly into the substitutions box, including slashes and quotes).

Technically this will turn $100 into "100 dollars" not "one hundred dollars", I'm sure number to text transliteration is possible in regex, I'm just not sure how off the top of my head lol


As an explanation in case you're not familiar:

$ looks for dollar symbols, however a $ on its own is a special character in regex that normally does something different so we use \$ to tell it to look for a literal dollar symbol.

[0-9\.] looks for any characters that are the digits 0 to 9 or a literal full stop(/period) character. [0-9\.]+ tells it to find at least one of those characters.

The curved brackets around it, ([0-9\.]+), turn it into a capture group, which basically says "hey, hold onto anything you find that matches the bit of pattern in this group".

In the replacement part "\1 dollars", the \1 tells it to replace this with the first (and in this case only) capture from the pattern.

So, for example, the following substitutions should work: