【发布时间】:2018-05-17 21:40:38
【问题描述】:
所以这是我的网址,我需要分成两部分。
1) http://localhost:8800/gb/
2) http://localhost:8800/gb/About.aspx
3) http://localhost:8800/gb/product.aspx?id=1&vref=201
4) http://localhost:8800/gb/Contact.aspx
现在告诉我应该使用哪个正则表达式来拆分上述网址。 第二部分将保存国家代码后的网址
假设这是我的网址http://localhost:8800/gb/About.aspx
所以第二部分将是 About.aspx
我有一个正则表达式(https?:\/\/[^\/]+)\/(.*) 将网址分成两部分,但我想从国家代码中获取。谢谢
【问题讨论】:
-
@anubhava 是的,您的代码有效 ` var url = 'localhost:8800/gb/About.aspx?id=2&vref=3'; var arr = url.split(/\/[a-z]{2}\//);警报(arr [0]);警报(arr[1]);`