content01
content01

Reputation: 3225

How to replace part of string using regex

I want to replace all the :

xmlns="http://xml.blablabla"

and

 xmlns:something="xxxx"

for a white space from a string.

Thanks

Upvotes: 0

Views: 1002

Answers (3)

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

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

Upvotes: 0

Pascal
Pascal

Reputation: 6030

String#sub is your friend:

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

Upvotes: 1

rid
rid

Reputation: 63442

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

Upvotes: 2

Related Questions