//string file.text:16: lots of random text here with goes on for ages //regex (.?)[:](.*) // group 1 returns 't'
Try this regex:
^ #Start of string ( #Start of capturing class #1 [^:] #Any character other than : + #One or more of the previous character class ) #End of capturing class #1 [:] #One : (.*) #Any number of characters other than newline
? operator captures zero or one of the previous symbol only.
You could also use string operations instead:
str = "file.text:16:"; var n = str.indexOf(":"); var fileName = str.substr(0, n); var everythingElse = str.substr(n);