0

I have a string of the format,

/d.phpsoft_id=369242&url=http://f.1mobile.com/mobile_software/finance/com.mshift.android.achieva_2.apk

and i need to edit this string using regular expression that the result string should start from http: ie the resultatnt string should be

http://f.1mobile.com/mobile_software/finance/com.mshift.android.achieva_2.apk

please help

3 Answers 3

1

For these types of situations, I prefer to go with readily available tools that will help provide a solution or at the very least will point me in the right direction. My favourite for regex is txt2re because it will output example code in many languages, including ruby.

After running your string through the parser and selecting httpurl for matching, it output:

txt='/d.phpsoft_id=369242&url=http://f.1mobile.com/mobile_software/finance/com.mshift.android.achieva_2.apk'

re1='.*?'   # Non-greedy match on filler
re2='((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))'   # HTTP URL 1

re=(re1+re2)
m=Regexp.new(re,Regexp::IGNORECASE);
if m.match(txt)
    httpurl1=m.match(txt)[1];
    puts "("<<httpurl1<<")"<< "\n"
end
Sign up to request clarification or add additional context in comments.

1 Comment

What if there are multiple url's in the params? How do you know you want the first match?
0
str = "/d.phpsoft_id=369242&url=http://f.1mobile.com/mobile_software/finance/com.mshift.android.achieva_2.apk"

str.spl­it("url=")­[1]

2 Comments

This will break if there is another url= anywhere else.
You're going to pass multiple url parameters? Define the requirements please.
0

Simple Answer

You need to do following

str = "/d.phpsoft_id=369242&url=http://f.1mobile.com/mobile_software/finance/com.mshift.android.achieva_2.apk"

start=str.index('http://')

resultant=str[start,str.length]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.