Think about two different highlight match in vim
Pattern 1.
syn match match1 /\$[^$ ]+\$/
Match $foo$
, $bar$
, $123$
Pattern 2.
syn match match2 /(\w+\|(\$[^\$]+\$)\@=)+__/
I want it match foo$bar$__
but not $bar$
The problem is Pattern1 will conflict with Pattern2.
I'm trying to use Positive Lookahead to bypass Pattern1 in Pattern2,
but the prefix __
(Double underscores) destroy the behavior of Positive lookahead.
How do I solve this issue? or i'm doing something wrong !?
Update:
Sorry for bad explanation.
Pattern 1 match any string surrounded by two dollar signs
syn match match1 /\$[^$ ]\+\$/
-> $foo$, $bar$
Pattern 2 match any string end with double underscores BUT match still but exclude any string that match as Pattern1.
syn match match2 /\(\w\+\|\(\$[^\$]\+\$\)\@=\)\+__/
-> hello__, world__
so the problem is when I add any string related to pattern 1
hello$foo$__
in this case. I want hello AND __ match with pattern 1(Continuous)
but also let $foo$ match with pattern 2.
(?:\w+\$[^$ ]+\$__|\$[^$ ]+\$)
. Don't need a lookahead really. Convert to vim syntax as needed. - user557597__
after a$aa$
(unless matched with afoo
before it), add the assertion after the\$[^$ ]+\$
clause, like this(?:\w+\$[^$ ]+\$__|\$[^$ ]+\$(?!__))
- user557597/\v\$[^$ ]+\$(_)@!/
. This will match words between dollar signs when not followed by underscore (example:$foo$
). For the second pattern:/\v\w+\$[^$]+\$__/
. This will match a word, followed by a word between dollar signs, followed by double underscore (example:foo$bar$__
) - MAGA