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.
如何在 ruby 中指定特定字符或特定字符gsub的子字符串?starts withenclosed by
gsub
starts with
enclosed by
例如:输入是:Prime rates[ U.S. Effective Date: 12/16/2008 ] 我想 gsub 由两个方括号 [ 和 ] 括起来的子字符串,并希望输出如下:Prime Rates
Prime rates[ U.S. Effective Date: 12/16/2008 ]
Prime Rates
如何使用 ruby 正则表达式来做到这一点?
也许是这样的:
s.gsub(/\[.*\]/, "")
[]假设此类子字符串不超过一次,这将删除包含在其中的任何内容。
[]