Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match the last element in a delimited list?

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.

like image 658
Alexis King Avatar asked Oct 16 '25 04:10

Alexis King


1 Answers

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

/[a-zA-Z0-9]*$/
like image 106
jbr Avatar answered Oct 17 '25 18:10

jbr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!