simple regex to splice out text in ruby
Posted
by user141146
on Stack Overflow
See other posts from Stack Overflow
or by user141146
Published on 2010-05-07T03:25:32Z
Indexed on
2010/05/07
3:28 UTC
Read the original article
Hit count: 331
I'm using ruby and I want to splice out a piece of a string that matches a regex (I think this is relatively easy, but I'm having difficulty)
I have several thousand strings that look like this (to varying degrees)
my_string = "adfa <b>weru</b> orua fklajdfqwieru ofaslkdfj alrjeowur woer woeriuwe <img src=\"/images/abcde_111-222-333/111-222-333.xml/blahblahblah.jpg\" />"
I would like to splice out the /111-222-333.xml (the value of this changes from string to string, but suffice it to say is that I want to remove the piece between 2 forward slashes that contains something.xml.
my hope was to find a match like this
my_match = my_string.match(/\/.+?\.xml\//)
but this actually captures "/b> orua fklajdfqwieru ofaslkdfj alrjeowur woer woeriuwe <img src=\"/images/abcde_111-222-333/111-222-333.xml/"
I assumed that .+? would match what I am looking for, but it seems like it starts with the first forward slash that it finds (even though it's non-greedy) and then expands forward to the ".xml").
Any thoughts on what I'm doing wrong?
TKS!!
© Stack Overflow or respective owner