简体   繁体   中英

ruby regular expression to gsub a particular portion of a string

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[ US 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?

Maybe something like:

s.gsub(/\[.*\]/, "")

This will remove anything enclosed in [] assuming there is no more than one occurrence of such substring.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM