1

I have two string in which I have to sorten urls. I want a regex pattern to extract them

https://l.facebook.com/l.php?u=http%3A%2F%2Febay.to%2F2EyH7Nq&h=ATNHM5kACc4rh_z68Ytw__cNCzJ63_iPezd_whc0PjcsN4qj1PfdJgFXyrOKM3-biqPm7eAXTOc5LD6r-7JXhRsqsqEHUs0jaJkjvm_QWf6sqbHQmS63q6P0_NcQoUa86Az5EttNT9xJb_evKBaiFxW7e7v2afJQn2zNxz5lQ8xgxhMcEFuJ3hUiSYUMEemKFB2LSIgAZFibRv4GeRrTk8hxFaArkBuAhQaXQFd4jX-aQuUYhjD0ErV5FY-D4gFMpb0lFCU7SyBlRpkUuOcHVjwjxN-_g6reMYwo8loAJnJD
/redirect?q=http%3A%2F%2Fgoo.gl%2FIW7ct&redir_token=PV5sR8F7GuXT9PgPO_nkBFLABQx8MTUxNjA3OTY5MEAxNTE1OTkzMjkw&v=7wmIyD1fM4M&event=video_description

Output will be from 1st and 2nd link:-

http%3A%2F%2Febay.to%2F2EyH7Nq
http%3A%2F%2Fgoo.gl%2FIW7ct

Please help me out. I have already used:- (http|https).*?&

but its not working on first url.

1

3 Answers 3

2

You can try this:

=(https?[^&]*)

Demo

If lookbehind is possible in your flavour of regex then you may try this as well which will ensure to not capture the equal sign:

(?<=)(https?[^&]*)

Demo 2

Sign up to request clarification or add additional context in comments.

2 Comments

Might be worth adding a capture group to make it easy to ditch the =... Or look-behind ;)
You are right MatBailie, in the mean time I was trying to just match the desired thing thus come the lookbehind regex. Btw added capture group to the first solution.
1

Try this regex !

I am also attach the output of the regex through regex101.

http%3A%2F%2F(.*)%2F(.*[^&])(?=&)

output

Comments

0

You can use this pattern to only capture goo.gl and ebay.to links:

(http%3A%2F%2F(ebay\.to|goo\.gl)%2F[^&]*)&

Demo

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.