Add extract from Regex (Java)

This commit is contained in:
chteufleur 2015-10-02 14:22:05 +02:00
parent cf3ad1cc32
commit 4a86bee82a
1 changed files with 12 additions and 0 deletions

View File

@ -5,3 +5,15 @@
public static boolean isIp(String ip) { public static boolean isIp(String ip) {
return ip != null && !ip.equals("") && ip.matches("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); return ip != null && !ip.equals("") && ip.matches("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
} }
public static void extractFromRegex(String str) {
Pattern pattern = Pattern.compile(".*@(.*)");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
if (matcher.groupCount() == 1) {
System.out.println("domaine: "+matcher.group(1));
}
}
}