I have a very simple regex question. Suppose I have 2 conditions:
How can I extract the baseUrl using regex?
Sample output:
Advertisement
Answer
Like this:
JavaScript
x
String baseUrl;
Pattern p = Pattern.compile("^(([a-zA-Z]+://)?[a-zA-Z0-9.-]+\.[a-zA-Z]+(:d+)?/");
Matcher m = p.matcher(str);
if (m.matches())
baseUrl = m.group(1);
However, you should use the URI
class instead, like this:
JavaScript
URI uri = new URI(str);