[英]Regex match a group not ending with specific string
我正在使用javascript正則表達式引擎,並且在使用正則表達式時遇到了困難:
這是一個示例(這是我必須匹配的丑陋的js腳本提取):
{data = function() {[{id:"1441-aeze",name:"theme1"},{id:"1441-aezb",name:"theme2"},{id:"1441-aezc",name:"theme3-a"},{id:"1441-aezd",name:"theme1-mtr"},{id:"1441-aezf",name:"theme4"}]}}
我的正則表達式嘗試:
id:"([^"]+)",name:"(?![^"]*mtr$)[^"]*"
匹配組1的預期結果:
Match[1] : 1441-aeze
Match[1] : 1441-aezb
Match[1] : 1441-aezc
Match[1] : 1441-aezf
但這與我樣本的每個部分都匹配。 我不明白為什么
這是reg101: Regex101示例
我不確定,您的預想中的$
應該做什么,但是在字符串的末尾(或帶有m-Modifier的行的末尾)未轉義的$
匹配-但末尾沒有行的末尾你的比賽。 在您的模式中, "
表示比賽結束,因此您只需將$
替換$
"
即可使其生效,例如id:"([^"]+)",name:"(?![^"]*mtr")[^"]*"
查看更新的鏈接: https : //regex101.com/r/tY1aG7/4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.