共同點
(?:pattern) 與 (?=pattern)都匹配分組,但不會把分組放到匹配結果中。
區別
(?:pattern) 匹配得到的結果包含pattern。
(?=pattern) 則不包含。
對字符串:"industry abc"的匹配結果:
industr(?:y|ies) ---> "industry"
industr(?=y|ies) ---> "industr"
是否消耗字符
(?:pattern) 消耗字符,下一字符匹配會從已匹配后的位置開始。
(?=pattern) 不消耗字符,下一字符匹配會從預查之前的位置開始,只預查,不移動匹配指針。
出處:https://www.jianshu.com/p/43af3e83e6e9