正则表达式替换双引号外的字符的所有出现

时间:2018-03-08 11:19:39

标签: regex

我正在寻找一个与ä字符匹配的正则表达式,但仅当它不在双引号内时。

我试图用负面看法来解决这个问题,不应该有双引号,后跟任何不是双引号的字符,但实际上只有偶数时间,这意味着1,3,5,等

尝试就像这样:(?<!("[^"]*(?:(?:"[^"]*){2})*?)?)ä

但它不起作用。

或者对于双引号后面的正面观察,然后是任何不是双引号但只有奇数次数的字符,这意味着0,2,4等

尝试就像这样:(?<=(?:(?:"[^"]*){2})*)ä

但它也不起作用。

所以我的所有尝试都失败了!这是我的测试字符串:

This ä is to replace
"This ä is not to replace"
"This ä is not to replace" but this ä is to replace
This ä is to replace but "this ä is not to replace"
This ä is to replace, "this ä is not to replace", this ä is again to replace
"This ä is not to replace", "this ä neither", but this ä is to replace
"This ä and this ä aren't to replace", but this ä and this ä are to replace
This is the ultimate mix: ä ä "ä ä ä" ä ä ä "ä ä" "ä" "ä ä" ä ä ä

0 个答案:

没有答案