Calvin:
find: a glyph followed by an em-dash followed by a glyph
apply: character style to the em-dash and the preceding glyph (since the tracking only applies to the space after a glyph when highlighting a single glyph)
Ehm… That's what this GREP does
.~_
I admit it's a tiny one, so perhaps that's why you didn't notice it. It's “any character followed by an em dash”. As you noticed, it's not necessary to apply it to the next character as well. It's therefore also not necessary to include it in the GREP style.
I've not quite wrapped my head around “look for this pattern but only apply the character style to these sub-elements of what you found”…any kind souls willing to point me in the right direction?
That can be done in two ways. The first way only works with find-and-replace, and to use it you have to “mark” groups of characters to find with parentheses, (like) (this) — two groups. In the Replace With field, you refer to the found groups using $1, $2, $3 etc. (“$0″ is a special code for the entire found expression). So you can switch these two words around by putting “$2 $1″ into the Replace field. It's especially handy if you need to find “abc” and change only the “b” part. But —
The other way to do it, is with Lookahead and Lookbehind. They are pretty cool features, with some amazing capabilities. What they do is look for text before and/or after what you want to find, but without marking them — they do not get highlighted when you press “Find Next”. Hence, they are not touched by anything you put in the Replace With field. Subscripting the “2″ in “H2O” is a good example, as you cannot do that with one regular Find/Replace. However, when Looking Behind for an “H”, searching for a “2″, and Looking Ahead for an “O”, you can do it in one go! This particular example would look like this:
(?<=H)2(?=O)
with this full explanation, provided by something I am (or should be) working on:
(?<= Lookbehind Group
H Literal text ‘H’
) End Lookbehind Group
2 Literal text ‘2’
(?= Lookahead Group
O Literal text ‘O’
) End Lookahead Group