简体   繁体   中英

Jquery Match URL before a special character

i want to match url till a special character '_' if it is present

var url = window.location; var url should get part of url before '_' http://www.example.com/index.php?route=product/category&path=25_10

ie http://www.example.com/index.php?route=product/category&path=25

split方法可以做到:

window.location.href.split('_')[0]
var href = window.location.href;
// http://www.example.com/index.php?route=product/category&path=25_10

var new_url = href.slice(0, href.indexOf('_'));
// http://www.example.com/index.php?route=product/category&path=25

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM