user697911
user697911

Reputation: 10531

vim search with bracket symbols

String:

abc|c|xyz

Pattern:

|[^|]*

I hope this will only match '|xyz', but it matches '|c|xzy'. Why is it that? My pattern means that "start with '|' and any following character can't be '|'". Right?

Upvotes: 0

Views: 263

Answers (1)

Jim U
Jim U

Reputation: 3366

Vim isn't matching "|c|xzy" There are two separate matches, "|c" and "|xyz". You can verify this by pressing n to jump between them.

It seems you only want the last match. You can add "$" to ensure your pattern only matches the end of a line:

|[^|]*$

Upvotes: 2

Related Questions