Regular expressions in Word
This is slightly off-topic (actually, quite a bit so!) but I’m writing a paper and just learned that you can do search-replace in Word with regular expressions. In my case, I had some inconsistencies in how inline citations were shown before or after punctuation. To solve this, I searched for:
(\([!\)]@ [!\)]@[0-9][!\)]@\)).
And replaced with (after checking the Use wilcards option):
. \1
There are at least three gotchas in the expression:
- The usual [^0-9] is replaced with [!0-9].
- Using + to give you one or more occurences of an expression won’t work. Instead, you use @ which makes no sense.
- Since * is being used to match any string of characters, the asterisk is unavailable to match zero or more occurences.
Having said that, the whole +/*/@ controversy can probably be avoided using {n,m} (ie. {0,} or {1,})