mbilyanov
mbilyanov

Reputation: 2511

How to satisfy this pattern comparison in vim script?

I came across the following string comparison in a vim script.

echo my_test_var =~ '\\\@<!`.*\\\@<!`'

I am trying to figure out, what should be the value of my_test_var so that the comparison returns 1.

Upvotes: 1

Views: 56

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626709

In Vim, the \@<! is a negative lookbehind construct that fails any match if it is preceded with the lookbehind pattern. Thus, the whole expression will match a string like

`some \`text\` here`

as

  • \\\@<!` - match a backtick that is not immediately preceded with a backslash
  • .* - matches 0+ characters, as many as possible
  • \\\@<!` - match a backtick that is not immediately preceded with a backslash

Upvotes: 1

Related Questions