我有两个字符串,check_urlcurr_url

<script>
var check_url='http://localhost/project/show/{dynamic content}';
var locationHref    =   $(location).attr('href');//current url
</script>


为此,我需要匹配两个字符串。
我尝试下面的代码

var urlslugRegex = '/^[a-z0-9-]+$/';
if(locationHref == 'http://localhost/project/show/'+(urlslugRegex)){
    alert("if");
}else{
    alert("else");
}

最佳答案

尝试这个

var urlslugRegex = '([a-zA-Z0-9_-]+)';
if(locationHref.match('http://localhost/project/show/'+(urlslugRegex)){
    alert("if");
}else{
    alert("else");
}

10-08 03:20