Author Topic: Issues with RegEx including {curly brackets}  (Read 2028 times)

Astan

  • Newbie
  • *
  • Posts: 22
Issues with RegEx including {curly brackets}
« on: March 18, 2024, 04:56:14 AM »
Apparently, VoiceAttack refuses to process RegEx expressions with curly brackets in them. The documentation is silent on this matter, and only describes the token {TXTREGEXREPLACE:}; it would be very helpful if it included a note on the limitations to RegEx, as processed through this token. Unless, of course, it's a bug.

At present, are there any workarounds to this?

I tested this with the token {TXTREGEXREPLACE:MyTxtVar:Match:Replace}, used in setting a (new) text variable, with "MyTxtVar" set to "15th of March", "Replace" set to "" (empty), and "Match" set to:
  • "\d\d\w\w\sof\s", which matched the first part of the date correctly (output: "March"),
  • "\d+\w+\sof\s", which also matched the first part of the date (output: "March"),
  • "\d{1,2}\w{2}\sof\s", which matched nothing (output: "15th of March").

Full command tested:
Code: [Select]
Set text [MyTxtVar] to '15th of March'
Set text [Match] to '\d{1,2}\w{2}\sof\s'
Set text [Replace] to "
Set text [ProcessedText] to '{TXTREGEXREPLACE:MyTxtVar:Match:Replace}'
Quick Input, '{TXT:ProcessedText)'

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Issues with RegEx including {curly brackets}
« Reply #1 on: March 18, 2024, 05:04:03 AM »
As mentioned in the documentation, literal curly braces need to be escaped with a pipe symbol ('|'), as otherwise the token parser will remove them.

This is not specific to the "{TXTREGEXREPLACE:}" token.


In this case, you could instead enable the "Do not render tokens in variable values" option for the action you're setting the "Match" value with (as the value isn't parsed by the token parser elsewhere).

Astan

  • Newbie
  • *
  • Posts: 22
Re: Issues with RegEx including {curly brackets}
« Reply #2 on: March 18, 2024, 06:34:06 AM »
Thank you, I stand corrected. Escaping the braces with the pipe symbol indeed works, and the extra variable option you mentioned is even more convenient in practice. This simply slipped me in the documentation.

That said, might I suggest moving the following part higher in that section ("Text (and Text-To-Speech) Tokens"), or adding bold to it, so that it's more emphasized:
Quote
With version 1.6 of VoiceAttack and later, tokens can be, ‘nested’. That means you can have tokens that accept the value of other tokens. Tokens are processed from the inner-most token to the outer-most token, reprocessing with each iteration. Also, anything contained within curly brackets { } that do not resolve to a token will be rendered as whatever is contained within the brackets. To indicate a literal curly bracket, simply prefix the curly bracket with a pipe symbol: |{ or |}.

Please also consider adding an extra note in the sub-section {TXTREGEXREPLACE:}, on this being crucial for that token to resolve properly.