RegEx lazy matching from end of string

Viewed 335

Is it possible to perform lazy matching from the end of a string?

Contrived Example:

let str = "It's the end of the world as we know it"
let regex = /n.+$/
str.match(regex)         //finds "nd of the world as we know it"

Simple enough, it finds 1 or more any character from the end of the string until it finds the last "n" (going backwards).

Now, however, let's say I want it to find 1 or more any character from the end of the string until it finds the first "n" (going backwards). You would think you could add the 'lazy' quantifier, like this:

let regexLazy = /n.+?$/

but the result would still be the same:

str.match(regex)         //finds "nd of the world as we know it"

Is it possible to do lazy matching when starting from the end of a string? What am I missing? Thanks!

0 Answers
Related