正則截取某開頭結尾中間的內容,但不包含開頭、結尾


原文 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"]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM