正则截取某开头结尾中间的内容,但不包含开头、结尾

原文 https://blog.csdn.net/qq_38111015/article/details/80416823



var
s = 'CN_11223sgsg-dsg23.mtl' var matchReg = /(?<=CN_).*?(?=.mtl)/; s.match(matchReg)

 

正则前瞻(?=)和非捕获性分组(?:)区别

(?=)会作为匹配校验,但不会出现在匹配结果字符串里面

(?:)会作为匹配校验,并出现在匹配结果字符里面,

var data = 'windows 98 is ok';
data.match(/windows (?=\d+)/);  // ["windows "]
data.match(/windows (?:\d+)/);  // ["windows 98"]
data.match(/windows (\d+)/);    // ["windows 98", "98"]

 

posted @ 2019-06-28 10:37  刘金宇  阅读(6421)  评论(0编辑  收藏  举报