0

I tried searching for something similar, and couldn't find anything. I'm having difficulty trying to replace a few characters after a specific part in a URL.

Here is the URL: https://scontent-b.xx.fbcdn.net/hphotos-xpf1/v/t1.0-9/s130x130/10390064_10152552351881633_355852593677844144_n.jpg?oh=479fa99a88adea07f6660e1c23724e42&oe=5519DE4B

I want to remove the /v/ part, leave the t1.0-9, and also remove the /s130x130/.I cannot just replace s130x130, because those may be different variables. How do I go about doing that?

I have a previous URL where I am using this code:

            if (pictureUri.indexOf("&url=") != -1)
            {
                String replacement = "";

                String url = pictureUri.replaceAll("&", "/");

                String result = url.replaceAll("().*?(/url=)",
                        "$1" + replacement + "$2");                 

                String pictureUrl = null;

                if (result.startsWith("/url="))
                { 
                    pictureUrl = result.replace("/url=", "");
                }
            }

Can I do something similar with the above URL?

1
  • What is ().*? supposed to be doing? Commented Nov 14, 2014 at 23:04

1 Answer 1

1

With the regex

/v/|/s\d+x\d+/

replaced with

/

It turns the string from

https://scontent-b.xx.fbcdn.net/hphotos-xpf1/v/t1.0-9/s130x130/10390064_10152552351881633_355852593677844144_n.jpg?oh=479fa99a88adea07f6660e1c23724e42&oe=5519DE4B

to

https://scontent-b.xx.fbcdn.net/hphotos-xpf1/t1.0-9/10390064_10152552351881633_355852593677844144_n.jpg?oh=479fa99a88adea07f6660e1c23724e42&oe=5519DE4B

as seen here. Is this what you're trying to do?

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

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.