View Full Version : RegExp question

09-22-2011, 09:11 PM
I have this string:

this is my test <a href="yay.html">yay</a>

and want to just match the part before the <a...:

this is my test

I can't figure out the regular expression for this. I've tried everything I can think of. It seems that it needs to do a non-greedy search on the first < it finds, but nothing works, like:


Please help, thanks!

09-22-2011, 09:47 PM
// this will give "this is my test "
var result = 'this is my test <a href="yay.html">yay</a>'.match(/(.*)<a/)[1]

09-22-2011, 10:04 PM
Thank you! Looks like I was making it harder than it was. :)