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.
ルビーの特定の文字または特定gsubの文字をサブストリングにするにはどうすればよいですか?starts withenclosed by
gsub
starts with
enclosed by
たとえば、:input is:Prime rates[ U.S. Effective Date: 12/16/2008 ] 2つの角括弧[と]で囲まれたサブ文字列をgsubし、次のような出力が必要です。Prime Rates
Prime rates[ U.S. Effective Date: 12/16/2008 ]
Prime Rates
ルビー正規表現を使用してそれを行うにはどうすればよいですか?
多分次のようなものです:
s.gsub(/\[.*\]/, "")
[]これにより、そのような部分文字列が1つしか出現しないと仮定して、囲まれているものがすべて削除されます。
[]