regex
to do relatively complex find and replace functions. For example, The Lancet requires that all decimal points be middle dots (i.e., interpuncts). This is pretty trivial in LaTeX or Rmd
and turns out it’s equally easy in Word.
Just use ([0-9]{1})(\.)([0-9]{1})
as your search query and \1·\3
as your replacement with the “Use wildcards” option.
We (as a field) should still be moving over to doing our drafting in Rmd
or LaTeX though. The bloat on MS Word makes working with moderate sized manuscripts with figures painful.
If that code is gibberish to you, I highly recommend learning some basic regex
. It will likely end up being one of those tools you rarely use and you’ll need to use Google or StackOverflow to assist you, but it can make complex string extraction much easier.
[0-9]
just means I want any character between 0 and 9. {1}
means I want exactly one of the thing to the left. \.
means I want a literal period. So the whole phrase means, “I want to find text where there is exactly one number to the left of a period and one number to the right of a period.”
The parenthesis just groups the query so I can refer to them later. Thus, the replacement is just saying, “Take the first group (\1
), add an interpunct (·
), then add the third group (\3
).”
Magic.
Update 1/17/21.
Several people have asked how to undo this — just copy an interpuct in your document and use regular find-and-replace to replace it with a period. The interpunct should be rare enough you don’t need regex to undo it. Hope that helps!