I am using Dynamic Hotstrings as part of my implementation of AutoHotkey. It has been an invaluable tool in the learning of Regular Expressions.

Currently I use it heavily for text expansion within my daily processes at the office. I am however having trouble within word processing software when using text formatting. In the case that I bold, italicize, or otherwise provide a modification to the format at the beginning of a string that would otherwise expand, it will not expand because the control character is part of the string. I have been using \b as the initial switch in my regex.

I am looking to see if there is a shortcut within the regex world to account for these kind of characters without enumerating them by hand. Does such exist?

If not, is there a handy reference of all the control characters I would need to account for in MS Word?

Thank you for your time.

  • 2
    Could you give a concrete example of what you're trying to do? – m4573r Oct 2 '12 at 14:20
  • I have this: hotstrings("\boic"tailchar,"Officer in Charge (OIC)%$1%") which takes the text "oic" and expands it even here. Of course the expression also "sees" the ctrl-b if I were to type the same in the word processor in bold. tailchar is simply a variable that holds all the characters I would like to signify and end to the string. – EFH Oct 2 '12 at 18:27
  • Updated the link to the newest version of the library. – EFH Dec 11 '14 at 18:49

With the example you gave in comments, I'd advise to just remove the \b in the beginning. It's of course not optimal, and it might trigger the expansion when you don't want it, but how often do you type words which end with "oic" anyway?

A more elegant solution would be to have something like this:

hotstrings("([^a-zA-Z])oic"tailchar,"%$1%Officer in Charge (OIC)%$2%")

But unfortunately I can't test this since I can't seem to make DynamicHotstring work :/

  • I like adding the negative at the front. It is an approach I will explore. – EFH Oct 2 '12 at 19:41
  • I was looking over my past questions and came across this stale one. Guess something shiny caught my attention. I took your idea and made it a look-behind operation so as not to need to pass %1%. This is what I have tested and found success with for the example given: hotstrings("(?<=[^a-zA-z])oic"tailchar,"Officer in Charge (OIC)%$1%"). It works with bold, I'll comment further if it falls apart in practice. I may end up doing a wholesale 'find and replace'! – EFH Dec 6 '14 at 17:50
  • Upgraded to the new version of the library. This fix no longer works. – EFH Dec 11 '14 at 19:43
  • @EFH Does it work if you just change the regex to "oic"? As in, does the library works at all? Also, if it was working for you before, there's no real reason to upgrade, I'd just keep the old version. – m4573r Dec 12 '14 at 11:03
  • The library works in both forms. Old and new. The new is less buggy and better adapted to working environments today as opposed to 4 years or so ago. The issue in Word with the text expansion failing immediately after a keystroke-initiated style change is minor. Though I was hoping to find a simple oversight on my part, it is not something I'll suffer much for not fixing. I have a query out in the forum of the current maintainer of this script. I'll see if that yields fruit for me. Yesterday I spent most the day exploring regex. Not a loss at all! – EFH Dec 12 '14 at 15:18

Regular expressions can only handle what you set it to handle. They don't assume that you have bold characters, or some other kind of formatting character. You will have to include these characters in your regular expression if you intend to capture them.



Making bold optional on either end:


I would see if there is a way to strip these out in the program that you're using. The only way you'll be able to avoid having to use the characters themselves is if the program strips them before it tries to match the regular expression.

  • I will look to find how the unseen characters are coded in MS Word than and add them to the regex. Thank you. I wanted to be sure I was not missing something obvious and easy to employ before I started listing unseen characters out in a variable. – EFH Oct 2 '12 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.