I'm trying to write a GtkSourceView language file to highlight some of my files in gedit. The problem I'm encountering is that I want to highlight words that contain at least the first four characters and are correctly spelled. To illustrate, say I have four patterns:
variable
vari
variab
variabel
and I want to identify the first three, but not the fourth, because the first three are all correctly spelled substrings of the target "variable". What gets the job done is using
\bvari(a|ab|abl|able)?\b
but this can become quite tedious with longer words. So in a full lang-file it would look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<language id="foo" _name="foo" version="2.0" _section="Other">
<metadata>
<property name="mimetypes">text/x-foo</property>
<property name="globs">*.foo</property>
</metadata>
<styles>
<style id="keyword" _name="Keyword" map-to="def:keyword"/>
</styles>
<default-regex-options case-sensitive="false"/>
<definitions>
<context id="foo">
<include>
<context id="keyword" style-ref="keyword">
<keyword>\bvari(a|ab|abl|able)\b</keyword>
</context>
</include>
</context>
</definitions>
</language>
I was not able to find a solution to this - because I'm extremely unfamiliar with regex and do not know the correct phrasing for this question. Is there a simple and efficient solution to this problem?