非贪婪的正则表达式并不是最接近的选择
发布时间:2020-12-14 06:31:08 所属栏目:百科 来源:网络整理
导读:我的正则表达式没有选择与内部文本最接近的’cont’对.我该如何解决这个问题? 输入: cont cont ItextI /cont /cont 正则表达式: cont.*?I(.*?)I.*?/cont 比赛: cont cont ItextI /cont 匹配我需要: cont ItextI /cont cont(?:(?!/?cont).)*I(.*?)I(?:(?
我的正则表达式没有选择与内部文本最接近的’cont’对.我该如何解决这个问题?
输入: cont cont ItextI /cont /cont 正则表达式: cont.*?I(.*?)I.*?/cont 比赛: cont cont ItextI /cont 匹配我需要: cont ItextI /cont cont(?:(?!/?cont).)*I(.*?)I(?:(?!/?cont).)*/cont 只会匹配最里面的块. 说明: cont # match "cont" (?: # Match... (?!/?cont) # (as long as we're not at the start of "cont" or "/cont") . # any character. )* # Repeat any number of times. I # Match "I" (.*?) # Match as few characters as possible,capturing them. I # Match "I" (?: # Same as above (?!/?cont) . )* /cont # Match "/cont" 这明确禁止在开头的cont和要捕获的文本之间(以及在该文本和结束/续)之间出现cont或/ cont. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |