xmlregexgeditgtksourceview

gtksourceview language file regex - look behind


I'm trying to extend the C language definition found in gtksourceview-3.0, the full original file can be found here. I just want to make a few syntax rules uses regex's, so I can syntax highlight stuff like functions, class members in gedit. Functions are easy enough, I just added my own context for them with a regex:

<context id="myfunc" style-ref="myfunc">
    <match>\w+(?=\()</match>
</context>

ie. then I can colour anything like function() by applying a style rule to myfunc. I'm finding it harder to do member variables, e.g. I want to colour the bar in foo.bar. Normally I'd use a look-behind regex like

<match>(?<=\.)\w+</match>

but it doesn't seem to work (and it breaks the other syntax highlighting rules!). At this point I'm stuck because I don't know which regex flavour is being used here, apparently it doesn't support look-behinds, and I don't know much about XML. Any suggestions?


Solution

  • Someone from the gedit mailing list answered me, apparently XML does not like the < character, it needs to be replaced:

    (?&lt;=...)
    

    It works then. The regex flavour is PCRE.