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