var reg = /.+?://.+?(/.+?)(?:#|?|$)/; var pathname = reg.exec( 'http://www.somedomain.com/account/search?filter=a#top' )[1];