2

次のような形式の文字列がいくつかあります。

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

「欲しい情報」だけを抽出したい。常に前に付けられ"\"start\":"、これは文字列内で 1 回だけ表示されます。これを行うためにどの正規表現を使用できますか?

4

4 に答える 4

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 に答える