Enabling Regular Expressions in AutoHotKey Script

I am currently developing a very "simple" script in AutoHotKey, but it includes using hotlines according to the format:

::btw::by the way

      

which will detect when the user types "btw" and replaces it with "btw".

However, when I try to set a regex between colons, it interprets it literally. Is there a way to use regular expressions with hot strings? Workarounds are accepted.

+3


source to share


1 answer


Hotstrings do not support REGEx,
but there are RegEx Powered Dynamic Hotstrings that I have never tried.

Another option is a Loop with an Input command inside it.
This will require a final character, such as a space.
Then you will have a script to parse what the Input command returns with RegExReplace.
Put the number in the regex in the capturing group and use it as a back reference in the replacement. But if the pattern always has a digit in the same place, I think it will take two steps (with RegExMatch) as shown in this working example:



loop
{
Input, retrieved, V, {space}
RegExMatch(retrieved, "[a-zA-Z0-9]{6}", match)
RegExMatch(match, "\d", output)
If (output != "")
Sendinput, {bs 7}%output%
}

      

Enter any sequence of six with five letters and one number,
press the space bar and it will replace the sequence with just a number.

+1


source







All Articles