Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中,获取匹配正则表达式的长度_Javascript_Regex - Fatal编程技术网

在Javascript中,获取匹配正则表达式的长度

在Javascript中,获取匹配正则表达式的长度,javascript,regex,Javascript,Regex,在Javascript中,如何获得正则表达式匹配的长度 例如,如果字符串为 str = "/abc/hellothere/andmore/" regexp是 reg = new RegExp('/abc/[^/]*/'); 那么我要16,长度为 /abc/hellothere/ 假设您确实希望正则表达式与示例输入匹配: var str='/abc/hellother/andmore/; var reg=new RegExp('/abc/[^/]*/'); 变量匹配=str.match(r

在Javascript中,如何获得正则表达式匹配的长度

例如,如果字符串为

str = "/abc/hellothere/andmore/"
regexp是

reg = new RegExp('/abc/[^/]*/');
那么我要16,长度为

/abc/hellothere/

假设您确实希望正则表达式与示例输入匹配:

var str='/abc/hellother/andmore/;
var reg=new RegExp('/abc/[^/]*/');
变量匹配=str.match(reg);
if(匹配项和匹配项长度){
console.log(匹配[0]。长度);

}
您确定正则表达式与字符串匹配吗?是的,现在。在str前面添加了一个“/”。