var result, pattern = /^https?:\/\/[^/]*(\/([^/?.]+|$))/; result = 'http://google.com/aaa?....'.match( pattern ); alert( result && result[1] );