import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?:[a-z][0-9a-z-.+]*:\\/\\/)?((?:(?:[a-z\\u00a1-\\uffff0-9_]+-?)*[a-z\\u00a1-\\uffff0-9_]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9_]+-?)*[a-z\\u00a1-\\uffff0-9_]+)*(?:\\.(?:[a-z0-9\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:\\/.*)?(?:\\?.*)?(?:\\#.*)?$";
final String string = "socks://www.example.com\n"
+ "10.1.1.1\n"
+ "10.1.1.2/4\n"
+ "10.1.1.3/0\n"
+ "10.1.1.0/8\n"
+ "10.1.1.5/32\n"
+ "10.1.1.6/35\n"
+ "10.1.1.7/36000\n"
+ "10.1.1.8/abcd\n"
+ "10.1.1.9-10.1.1.10\n"
+ "user:pass@zxuz.com\n"
+ "user@proxy.brew.opendnstest.com/customBlockUserInfo\n"
+ "user:@proxy.brew1.opendnstest.com/customBlockUserInfo\n"
+ "user:password@proxy.brew2.opendnstest.com/customBlockUserInfo\n"
+ "ftp://cnn.example.com&story=breaking_news@foobar.com/top_story.htm\n"
+ "foo.com:8080/bar/baz\n"
+ "asdfasdf.com/foo/b%20ar\n"
+ "https://example.com/archive/*/http://somesite.com\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | 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