2

我有一些格式如下的字符串:

"text that comes before\"start\":\"Desired Info\"text that comes after"

我只想提取“所需信息”。它总是在前面,"\"start\":"并且它只会在字符串中出现一次。我可以使用什么正则表达式来做到这一点?

4

4 回答 4

2

This shall work:

s = "text that comes before\"start\":\"Desired Info\"text that comes after"

s[/(?<="start":")[^"]*(?=")/]
# => "Desired Info"
于 2013-11-02T19:00:48.253 回答
0

这里:是正则表达式:

"start":"(.*)"

在代码中:

match = /"start":(.*)"/.match("text that comes before\"start\":\"Desired Info\"text that comes after");

if match
    print match[1]
end
于 2013-11-02T18:48:09.643 回答
0

最简单的是:

s[/"start":"(.*?)"/, 1]
#=> "Desired Info"
于 2013-11-03T00:13:29.403 回答
-2
(?:\\"start\\":\\")(.+)(?:\\")

“所需信息”进入 NON IGNORED 捕获组。

于 2013-11-02T19:05:26.927 回答