与正则表达式匹配

时间:2013-10-16 00:50:24

标签: regex sublimetext2

我有一个字符串:

{
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
}

如何在, "Some Text"之前匹配每行的最后}? 顺便说一句,这是Sublime Text,我正在尝试这样做。这些值不像我在这里有的那样一致,我有几百行要替换。

我尝试, ".*",但匹配, "Some Text's, "Some Text"

3 个答案:

答案 0 :(得分:1)

我不使用Sublime Text,但如果它支持前瞻,那么, ".[^"]*"(?= })应该可以解决问题。

答案 1 :(得分:1)

你可以通过几种方式解决这个问题。

选项#1我们匹配第一组,然后捕获第二组,包括组\1$1中的逗号

"[^"]*"(, "[^"]*")

请参阅live demo

选项#2我们使用预先查找匹配的集合。

, "[^"]*"(?= \})

请参阅live demo

选项#3我们可以匹配整个字符串,我们的匹配包含在捕获组\1$1

\{[\S\s]*?(,\s+"[^"]*")\s+\}

请参阅live demo

答案 2 :(得分:0)

以下内容应该有效(使用前瞻):

("Some Text")(?= \}\,)

捕获的文本将在第一个匹配的组中找到

链接到 Fiddle