How to replace part of string using regex
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.
精彩评论