import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "https?:\\/\\/(?:www\\.)?([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b)*(\\/[\\/\\d\\w\\.-]*)*(?:[\\?\\;])*(?:[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=\\;]*)*";
final String string = "https://regex101.com/\n"
+ "ftp://daqdsqdq\n"
+ "azd ade zef ezfhttps://toto.dsdaz?page=1#sldlsdlsd&sqdqsd#sqdqsdsdza\"ad azd azd\n"
+ "azd ade zef ezfhttps://toto.dsdaz?page=1#sldlsdlsd&sqdq;sd#sqdqsdsdza\"ad azd azd\n"
+ "# OpenWrt Build System (PGP key for unattended snapshot builds)\n"
+ "curl 'https://git.openwrt.org/?p=keyring.git;a=blob_plain;f=gpg/626471F1.asc' | gpg --import \\\n"
+ "curl 'https://git.openwrt.org/?p=keyring.git;a=blob_plain;f=gpg/626471F1.asc' | gpg --import \\\n\n"
+ "from https://raw.githubusercontent.com/openwrt/docker/6d75cb142cba919faa74743c27c97b64c679a56a/docker-common.sh\n"
+ "# OpenWrt Build System (PGP key for unattended snapshot builds)\n"
+ "curl 'https://git.openwrt.org/?p=keyring.git;a=blob_plain;f=gpg/626471F1.asc' | gpg --import \\\n"
+ " && gpg --fingerprint --with-colons '<pgpsign-snapshots@openwrt.org>' | grep '^fpr:::::::::54CC74307A2C6DC9CE618269CD84BCED626471F1:$' \\\n"
+ " && echo '54CC74307A2C6DC9CE618269CD84BCED626471F1:6:' | gpg --import-ownertrust\n\n"
+ "https://www.asd.google.com/search?q=some+text¶m=3#dfsdf\n"
+ "https://www.google.com\n"
+ "http://google.com/?q=some+text¶m=3#dfsdf\n"
+ "https://www.google.com/api/?\n"
+ "https://www.google.com/api/login.php\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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