You can use
/[^/.]*.[^/]*$/ // The whole match is the required result
/.*/([^/.]*.[^/]*)$/ // and extract Group 1 contents
See the regex demo #1 and regex demo #2.
The second one is more efficient in practice, as the part after last /
is usually closer to the end of a longer string, and the match is usually obtained faster.
Details
[^/.]*
- zero or more chars other than .
and /
.
- a dot
[^/]*
- zero or more chars other than /
$
- end of string.
JavaScript demo:
const texts = [ 'a/b/c', 'a/b/c.a' ];
texts.forEach( text => {
console.log( text, '(/[^/.]*.[^/]*$/) =>', (text.match(/[^/.]*.[^/]*$/)?.[0] || "No match") );
console.log( text, '(/(.*/([^/.]*.[^/]*)$/) =>', (text.match(/.*/([^/.]*.[^/]*)$/)?.[1] || "No match") );
}
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…