How to make regular expressions work with track changes?
October 31, 2007 9:42 AM   Subscribe

How can I make Microsoft Word's Find-and-Replace feature work properly with regular expressions when Track Changes is on?

I'm working on a document containing a significant number of citations with page ranges. Many of those page ranges are separated by hyphens, and I need them to be separated by en dashes instead.

So I'm using Find and Replace with regular expressions like so:
Find what: ([0-9]{1,5})-([0-9]{1,5})
Replace with: \1–\2

Here's the problem: If I run Replace All on the test sentence, "Read pages 35-66, 87-92, & 105-22," I get back "Read pages 35–66, 87–92, & 105–22." Perfect. But if I turn on Track Changes and run it, I get "Read pages 3566–, 8792–, & 10522–." I need these changes to be tracked. Am I doomed to doing them by hand?
I realize how this question looks to people who aren't grammar nerds or law students. Trust me when I say that there is a difference, that the difference matters, and that the changes have to be tracked.
posted by Partial Law to Computers & Internet (6 answers total)
Assuming that the page numbers are generated dynamically using cross-references, but the hyphens are manual, why not just find and replace all hyphens with en dashes and then just go through each choice one at a time to determine whether or not to replace each one (i.e. don't replace all, but manually determine whether the relevant hyphen is in a page range citation?) If the hyphens are being generated by Word from the fields that give the page numbers, you can probably change the character it uses to generate them by updating the field codes.

Also try viewing the resultant document and see how that looks. Sometimes track changes will display strangely. It's somewhat buggy and gets to be too cumbersome when there are heavy revisions.
posted by jcwagner at 10:06 AM on October 31, 2007

Interesting bug :P

Not a complete solution, but.. Just using replace "-" with "–", and choosing Replace or Next one hit at a time will save a lot over a truly manual change.
posted by Chuckles at 10:10 AM on October 31, 2007

I would agree with JC.

Try this Find & Replace instead:

Find what: -

Replace with: ^+

The ^+ is the symbol for the em dash-- or the wider dash you desire.
posted by iam2bz2p at 10:15 AM on October 31, 2007

Response by poster: Thanks for the suggestions so far.
Unfortunately, the page ranges are citations to other sources, so they are not internal cross-references. Also, the changes as I pasted them in are how they turn out once you accept all changes.
I may end up using find and replace one at a time method, but there are a crapload of proper hyphens in the piece (it's primarily an article about the "something-somethingelse division" in law which would slow me down quite a bit.
Also, iam2bz2p, while this doesn't matter too much, I'm talking about the en dash, whose symbol is ^=. I've tried doing the F&R using that instead, with identical results. I guess at the very least I can file a bug report.
posted by Partial Law at 10:38 AM on October 31, 2007

Best answer: A little experimentation with your example showed that the bug seems to manifest itself only when the end of the "replace with" string is a sub-expression (e.g. \2.) So you could try the following. It isn't as comprehensive as your original find/replace, but is a little better than looking for every dash.

Find what: ([0-9]{1,5})-
Replace with: \1–
posted by metric space at 10:52 AM on October 31, 2007

Oh, another hack possibility.. Use regular expressions to replace all the regular hyphens with a place holder, use find and replace on the remaining hyphens, and switch the regular hyphens back.

You might have to do some track changes jiggery-pokery, because this might add a lot of noise, but..
posted by Chuckles at 10:55 AM on October 31, 2007

« Older Ranked preference in an HTML form?   |   I need to be insulted! But use your native tongue. Newer »
This thread is closed to new comments.