javascript - matching filename base -


still learning regex here need little help.

i have string assets/bigbluesomething_tn.jpg

i need match bigbluesomething

closest got `[^\/][a-za-z]+_

problem keep matching underscore i've tried [^\/][a-za-z]+[^_] @ advice several other threads no avail.

i'm writing in javascript, believe there regex things dont work in language.

this should give need:

var str = 'assets/bigbluesomething_tn.jpg'; var match = str.split('/')[1].match(/[a-z]+/i)[0]; 

edit: used split because otherwise you'd have loop matches extract need. match doesn't capture groups.

'assets/bigbluesomething_tn.jpg'        -^---------------------^- // .split('/')[1]        -^--------------^- // .match(/[a-z]+/i)[0]  [a-z] // match character z + // @ least 1 time /i // case-insensitive match a-z 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -