Pergunta

In vim I would like to use regex to highlight each line that ends with a letter, that is preceeded by neither // nor :. I tried the following

syn match systemverilogNoSemi "\(.*\(//\|:\).*\)\@!\&.*[a-zA-Z0-9_]$" oneline

This worked very good on comments, but did not work on lines containing colon. Any idea why?

Foi útil?

Solução

Because with this regex vim can choose any point for starting match for your regular expression. Obviously it chooses the point where first concat matches (i.e. does not have // or :). These things are normally done by using either

\v^%(%(\/\/|\:)@!.)*\w$

(removed first concat and the branch itself, changed .* to %(%(\/\/|\:)@!.)*; replaced collection with equivalent \w; added anchor pointing to the start of line): if you need to match the whole line. Or negative look-behind if you need to match only the last character. You can also just add anchor to the first concat of your variant (you should remove trailing .* from the first concat as it is useless, and the branch symbol for the same reason).

Note: I have no idea why your regex worked for comments. It does not work with comments the way you need it in all cases I checked.

Outras dicas

does this work for you?

^\(\(//\|:\)\@<!.\)*[a-zA-Z0-9_]$
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top