Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のような形式の文字列がいくつかあります。
"text that comes before\"start\":\"Desired Info\"text that comes after"
「欲しい情報」だけを抽出したい。常に前に付けられ"\"start\":"、これは文字列内で 1 回だけ表示されます。これを行うためにどの正規表現を使用できますか?
"\"start\":"
ここに: は正規表現です:
"start":"(.*)"
コード内:
match = /"start":(.*)"/.match("text that comes before\"start\":\"Desired Info\"text that comes after"); if match print match[1] end
最も簡単なのは次のとおりです。
s[/"start":"(.*?)"/, 1] #=> "Desired Info"