I have lines that are of the type @variable a 2
, from the beginning of the line. The keyword and its identifier @variable
are known and fixed. The variables can have [_a-zA-Z]
as the first character and then for the second character numbers, too, or combinations. They are separated by at least a space from variable
, and at least a space from the value, which can be an expression, too, like (1+2)/2
, or some other variable b
, thus it starts with either a number, a letter, or a parenthesis. What follows after that in the line can be a lot of things, unimportant (among which also newline).
What I want to do is match the variable, but only if it's the first thing that comes after variable
and is followed by a value or expression. This is what I have after the last attempt:
<context id="variable-noequal" style-ref="variable">
<match extended="true">
(((variable|variabel)\b\s+)?)
(([_a-zA-Z][_a-zA-Z0-9]*))
(?=((\s+)|(\s*\n)))
</match>
</context>
I have tried various combinations (the hammer was involved, too), but I can either get no match, or match every match of a variable that might be following (like a 2 for goodness sake). Backwards looking always gives a lookbehind not fixed
or some such error. I have also tried with prefix/suffix/keyword
, where keyword
was the fuzzy match you see above, but that didn't work, either. Searching the net revealed \K
, which does nothing for me. I know that the match could be better, for example, as it is, a simple underscore could pass on as a variable, I think I can make that, but for now I just want to see it properly highlighted. I should probably mention I'm not versed in PCRE. Is there a fix for this?
Sorry, I forgot to add this is in GtkSourceView for gEdit, but that is based on PCRE, I think(?).
@variab(le|el)\s+[_a-zA-Z][_a-zA-Z0-9]*(?!\S)
, see regex101.com/r/j3otIZ/1. If it does not match what you expect, please explain what should be matched. – Wiktor Stribiżewa
, to be matched, not the whole thing until after it. If you try my code, it matchesa
, but also anything else that comes after it and looks like a variable, for examplea 2 b 3
,b
is highlighted, too. It should also only work when there's@variable
before, if you start deleting chars, it's highlighted, too. I want the matching to start right beforea
, stop right aftera
, and only after (nonhighlighted)@variable
. – a concerned citizen@variab(?:le|el)\s+\K[_a-zA-Z][_a-zA-Z0-9]*(?!\S)
. If it is .NET compatible, use(?<=@variab(?:le|el)\s+)[_a-zA-Z][_a-zA-Z0-9]*(?!\S)
– Wiktor Stribiżew*.lang
file for gEdit, it doesn't. As I mentioned, I already tried\K
, but didn't work. Also, the 2nd method gives me thatlookbehind assertion is not fixed length
, again. I don't understand. Does GtkSourceView not support\K
or?<=
(which I have to use as?<=
to work)? – a concerned citizen@variab(?:le|el)\s+[_a-zA-Z][_a-zA-Z0-9]*\b
in the parent context, and the[_a-zA-Z][_a-zA-Z0-9]*
in the subcontext. – Wiktor Stribiżew