import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:https?:\\/\\/)?(?:www\\.)?plus\\.google\\.com\\/([\\w]+\\/)?([\\d]\\/)?([+]?[\\w(\\_\\-)?p\\{L\\}]+|[\\d]{21})(?:\\/)?(?:[\\w(\\-\\_)?]+)?";
final String string = "https://plus.google.com/+google/posts\"\n"
+ " , \"https://plus.google.com/+google/about\"\n"
+ " , \"https://plus.google.com/+google/photos\"\n"
+ " , \"https://plus.google.com/+google/videos\"\n"
+ " , \"https://plus.google.com/+google/plusones\"\n"
+ " , \"https://plus.google.com/+google/reviews\"\n"
+ " , \"https://plus.google.com/asdasda/104645458102703754878\"\n"
+ " , \"https://plus.google.com/u/0/LONGIDHE-RE\"\n"
+ " , \"https://plus.google.com/u/0/+JoseManuelGarcĂa_ertatto\"\n"
+ "https://plus.google.com/b/101789019230490914475/101789019230490914475/";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html