开发者

How to replace part of string using regex

开发者 https://www.devze.com 2023-03-18 16:14 出处:网络
I want to replace all the : xmlns=\"http://xml.blablabla\" and xmlns:something=\"xxx开发者_C百科x\"

I want to replace all the :

xmlns="http://xml.blablabla"

and

 xmlns:something="xxx开发者_C百科x"

for a white space from a string.

Thanks


str.sub!(/xmlns=.+?"/, ' ')


String#sub is your friend:

my_string = '<Fare_MasterPricerCalendarReply xmlns="http://xml.blablabla">'
my_string.sub(/\s.+$/, " >")
# => "<Fare_MasterPricerCalendarReply >"


Use this regex: xmlns="[^"]*", it matches xmlns="http://xml.blablabla", then replace match with empty string.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号