Reply To: GREP Style question

#61641

Lots of ways to skin this particular kitten. For example, this very short one may be all that's needed:

(?<=m)d

– it works on all of your examples :)

But I can see where you are heading for, you only want to superscript the digit for [digit][space][measurement][²³]. In that case you were very close indeed, but the only point of failure is this:

You cannot use lookbehind strings of variable length.

So that's why your (cm|m|km) doesn't work — this string may be either 2 or 3 characters long. The workaround trick is to use | to separate two lookbehinds, and whatever matches first will work:

((?<=d [kc]m)|(?<=d m))db

I added a b “Word break” at the end to ensure no digit or letter should follow the superscript number.


The trick to post a single backslash is to insert two of 'em \ when posting. If you edit your post, they will be reverted to a single backslash again so then you have to hunt through your text, \doubling\ all of them again :( (Edit: I just noticed a typo, of all things right smack in the middle of my “good” GREP, so I had ta do just that! :p )

This article was last modified on February 16, 2012

Comments (0)

Loading comments...