Reputation: 9047
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).
Upvotes: 0
Views: 3073
Reputation: 1264
A powerful and maintainable manner it to Java URL.class, then, you can mix with Regex
Upvotes: 0
Reputation: 132972
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
}
Upvotes: 1
Reputation: 10367
use this regex for checking and grabbing url:
\[\w+\s+url="(?<urllink>)[^"]*"\s*]
and get gorup named urllink
Upvotes: 2
Reputation: 47280
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.
Upvotes: 0
Reputation: 5326
Android provides several function for this purpose. SOme of this are:
Upvotes: 0