大家帮忙看看我的正则表达哪里写错啦
本帖最后由 qq245282209 于 2013-11-06 18:39:20 编辑
http://localhost:8081/sand/teach/D2/10
http://localhost:8081/sand/teach/D2/10/setting
http://localhost:8081/sand/teach/D2/10/param
http://localhost:8081/sand/teach/D2/10/sale
我这主要是通过url来识别给那一个下面加active样式就是红色的下划线
但是我的正则表达式匹配出错了,上面四个url都和图片第一个正则表达url.match(/(\/teach\/)[-a-zA-Z0-9]{0,62}(\/\d)+/g)匹配成功,而后面三个都匹配不成功,帮忙看看是哪里写错了。
------解决方案--------------------
var regx = /\/teach\/[-a-zA-Z0-9]{0,62}\/\d+(?:\/(.*))?$/,
url = "http://localhost:8081/sand/teach/D2/10/xx";
var result = url.match(regx);
if(result[1]){
$('#tech-course-round-' + result[1]).addClass("");
}else{
$('#tech-course-round-index').addClass("");
}
------解决方案--------------------(\/\d)
+