[英]Java regex. Match any “value” that is no preceded by given string
我需要有关Java regexp的帮助。 我正在使用具有类似JSON格式的文件:
['zul.wgt.Label','f6DQof',{sclass:'class',style:'font-weight: bold;',prolog:' ',value:'xxxx'},{},[]],
['zul.wgt.Label','f6DQpf',{sclass:'class notranslate',style:'font-weight: bold;',prolog:' ',value:'xxxx'},
['zul.wgt.Label','f6DQof',{sclass:'class',style:'font-weight: bold;',prolog:' ',label:'xxxx'},{},[]]
['zul.wgt.Label','f6DQof',{sclass:'class',style:'font-weight: bold;',prolog:' ',label:'xxxx'},{},[]]
我需要匹配sclass
属性上未带有“ notranslate ”值的任何label
或value
数据。
我一直在研究几乎可以正常工作的正则表达式,但是我需要最后的推动才能使其与我以前编写的内容相匹配
((?!.*?notranslate)sclass:'[\w\s]+'.*?)((value|label):'(.*?)')
现在,它匹配来自sclass
任何内容,且不带'notranslate'
谢谢你的帮助
您当前正则表达式的值在第4个捕获组中
您还可以使用1个捕获组,而不是4个:
^(?!.*\bsclass:'[^']*\bnotranslate\b[^']*').*\b(?:label|value):'([^']+)'
那将匹配:
^
字符串的开始 (?!
负向前进,断言右边没有
.*\\bsclass:
匹配任意字符0次以上,然后匹配class:
'[^']*\\bnotranslate\\b[^']*'
在单引号和单词边界之间匹配notranslate
)
关闭非捕获组 .*
匹配任何字符0+次 \\b(?:label|value):
匹配标签或值,后跟:
'([^']+)'
Match '
,在不匹配'
1+次的组中捕获并匹配'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.