Reputation: 34338
How to gsub
a sub-string that starts with
a particular character or enclosed by
particular characters in ruby?
As for example :input is : Prime rates[ U.S. Effective Date: 12/16/2008 ]
I want to gsub the sub-string that is enclosed by two square braces [ and ] and want output like : Prime Rates
How can I do that using ruby regular expression?
Upvotes: 1
Views: 132
Reputation: 70939
Maybe something like:
s.gsub(/\[.*\]/, "")
This will remove anything enclosed in []
assuming there is no more than one occurrence of such substring.
Upvotes: 3