我正在尝试使用sublime
修复带正则表达式的文本文件文本包含
的实例.. "description": "some description", "address": "some address", ...
由于某种原因,我的实例看起来像
.. "description": "some description", "some address", ...
所以我想找到那些有问题的并插入"address":
。
我试图用
的负向前瞻来做这件事\"description\":\s*\".*?\"\,\s*(?!\"address\"\:)
但它会找到每个实例,而不仅仅是description
后面没有address
我做错了什么?
答案 0 :(得分:1)
你的模式的问题是在负面向前看之前的最后\s*
抛出模式,试试这个
(\"description\":\s*\"[^"]*\"\,)(?!\s?\"address\"\:)
并替换为$1"address":
Demo
( Capturing Group \1
\" """
description "description"
\" """
: ":"
\s <whitespace character>
* (zero or more)(greedy)
\" """
[^"] Character not in [^"]
* (zero or more)(greedy)
\" """
\, ","
) End of Capturing Group \1
(?! Negative Look-Ahead
\s <whitespace character>
? (zero or one)(greedy)
\" """
address "address"
\" """
\: ":"
) End of Negative Look-Ahead
答案 1 :(得分:0)
您可以搜索此正则表达式:
("description":\s*"[^"]*\"\s*,\s*")(?!address")([^"]*".*$)
并替换为:
$1address": "$2