0

I have a string containing a short-code which looks like the one below:

some text...
[video url="http://www.example.com/path/to/my/video.ext"]
...some more text...

I want to be able to first check if the string contains that short-code and second extract the URL from it in Java (specifically Android).

5 Answers 5

2

use this regex for checking and grabbing url:

\[\w+\s+url="(?<urllink>)[^"]*"\s*]

and get gorup named urllink

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

Comments

1

try as:

   String str = "[video url=\"http://www.example.com/path/to/my/video.ext\"]";
    if (str.contains("url=\""))
    {
        int indexoff = str.indexOf("url=\"");
        int indexofff = str.indexOf("\"]");
        String strurl = str.substring(indexoff, indexofff - indexoff);
        strurl = strurl.Replace("url=\"", ""); //get url string here

    }

1 Comment

This what I used at last, but strangely it cut the string 7 characters short. So I had to add 7 to indexofff - indexoff manually!
0

Android provides several function for this purpose. SOme of this are:

Comments

0
String url = "whatever"
Boolean myBool = url.contains("ate");

String contains. Not sure what extract url means, but the string class has lots of useful functions.

1 Comment

Extracting the URL means I need that URL in a separate var.
0

A powerful and maintainable manner it to Java URL.class, then, you can mix with Regex

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.