Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
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

2 Answers 2

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 :/

share|improve this answer
    
I like adding the negative at the front. It is an approach I will explore. –  EFH Oct 2 '12 at 19:41

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.

Example:

/\bsomething\b/

Making bold optional on either end:

/\b\u0002*something\u0002*\b/

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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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