[Tex/LaTex] Help with custom syntax highlighting for TeXworks

syntaxtexworks

I recently learned of the option to make a custom syntax highlighting system for texworks as laid out in the texworks manual
If you go to the *\customizing texworks\syntax highlighting*section of the manual it tells you to edit the syntax-patterns.txt file.

Anyway what I'm trying to do is to highlight any of the latex lengths\measurements such as cm, mm, in, em in pink.
I 1st tried pink N (pt|mm|cm|in|ex|em)
but the problem with that is that words such as "*in*terview" or "*em*power" will have these letters go pink too.
The actual lengths will only appear after a digit so I need to stipulate some kind of condition for it to do that.

My own research on the matter has lead me down the path of the lookbehind feature for regular expressions which you can read about here
The best I've been able to come up with is

pink    N   (?<=\d)pt|mm|cm|in|ex|em

but this doesn't work.
Any help is appreciated.

Best Answer

You can realise that with

pink   N    (?=\d+)(pt|mm|cm|in|ex|em)

(?=\d+) checks if there is at least one (+) occurrence of a digit (\d). If there is, the listed character-combinations will be printed in pink. It's important to group them in braces, otherwise the (?= )-check would only affect the first character-combination; the others would be printed pink in any case. This works only if there's no space between digits and unit.

Related Question