문제

I have some data that is separated by colons, like this:

foo:bar:baz:qux

I want to use regex to match the last element, in this case, qux. The list may be of any length, and if it is one element long, there will be no colons at all.

I've tried using vim's zero-width matching constructs, but I can't seem to get it to do what I want.

도움이 되었습니까?

해결책

Use the $ anchor, which means the regex must match to the end of line.

/[a-zA-Z0-9]*$/

다른 팁

:\?[^:]\+$

This is optional colon followed by one or more non-colon characters followed by the end of the line.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top