0

So, I have a string like this:

str1 = "blablablabla... original_url=\"https://facebook.com/125642\"> ... blablablabla..."

what is the best approach to extract this original_url?

what I have done so far is this:

original_url = str1['content'][str1['content'].index('original_url')+12..str1['content'].index('>')-2]

it works, but it seems such like a poor solution, mostly I'm stuggling to find this substring /">

here's what I have tried so far

str1.index('\">')
str1.index('\\">') # escaping only one backslach
str1.index('\\\">') # escaping both back slash and "
str1.index("\\\">") # was just without idea over here

I'm not a ruby programmer, so I'm kinda lost here

Raul Quinzani
  • 493
  • 1
  • 4
  • 16

1 Answers1

0

The best approach to parse xml namespaces is to use Nokogiri as suggested by @spickermann.

Quick but not elegant and not even efficient solutions:

str1 = "blablablabla... original_url=\"https://facebook.com/125642\"> ... blablablabla..."

original_url=str1[str1.index("original_url")+14...str1.index("\">")] 
# => "https://facebook.com/125642" 

original_url=str1.split(/original_url=\"/)[1].split(/">/).first
# => "https://facebook.com/125642"
MVP
  • 1,061
  • 10
  • 8