var str='http://localhost/test/aabb/test3.htm?aa=bb';
var reg = /[^/][^/]+(?=\?)/gi;
alert(str.match(reg));