Joseph
Joseph

Reputation: 7755

Get Words After Last Dot in Regex and JS

How do I get the word after the last dot using Regex and JS?

const yeah = 'SampleLibrary/21.0/Best.colour'

const hello = yeah.replace('(?<=\.|^)[^.]+$')

console.log(hello)

EXPCTECTED OUTPUT

colour

Upvotes: 1

Views: 39

Answers (1)

Michael M.
Michael M.

Reputation: 11070

This should work:

const yeah = 'SampleLibrary/21.0/Best.colour'
const hello = yeah.replace(/^.+\./, '');
console.log(hello)

Upvotes: 1

Related Questions