[英]Regex Match % but not \%
I'm struggling to find the right regex for the case where I want to match a '%' but only if it's not preceded by a '\\' between quotations. 我要为想要匹配'%'的情况找到正确的正则表达式,但前提是在引号之间不加'\\'。
For example I want this to come back as a match 例如,我希望这个作为比赛回来
Test \\" this % matches \\" test
测试“此%匹配”测试
But not match 但不匹配
Test \\" this \\% doesn't match \\" test
测试\\“这个\\%不匹配\\”测试
Would a regex master be willing to assist me with this?! 正则表达式大师会愿意协助我吗?
Ultimately my goal is to ensure every '%' is escaped when found within quotations. 最终,我的目标是确保在报价中发现每个'%'时都转义。
Edit: Here's what I have right now 编辑:这是我现在拥有的
This is currently what I have but definitely isn't correct. 这是我目前拥有的,但绝对不正确。
\\". [%][^\\%]. \\"
\\“。 [%] [^ \\%]。
([^\\]|\\[^%])*
It looks like this seems to work in my tests on https://regex101.com/ 看来这似乎在我对https://regex101.com/的测试中起作用
The sections are ( [^\\\\] | \\\\[^%] )*
这些部分是
( [^\\\\] | \\\\[^%] )*
The ()*
means 0 or more of the contained group. ()*
表示包含的组中的0个或多个。
The contained group is either [^\\\\]
or \\\\[^%]
. 所包含的基团是
[^\\\\]
或\\\\[^%]
。 The first case is "any character that is not a backslash," which include the percent sign. 第一种情况是“不是反斜杠的任何字符”,其中包括百分号。 The second case is "a backslash followed by any character that is not a percent sign."
第二种情况是“反斜杠后跟不是百分号的任何字符”。
The [^ ]
operator is "any character except these." [^ ]
运算符是“除这些字符外的任何字符”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.