UUID regex
Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Main {
public static void main(String[] args) {
String[] uuids = {
"8fff4739-5f85-452d-8955-b0b0ace74bf7",
"a1234567-1023-4984-9429-029183c02b1",
"a1234567-1023-4984-9429-029183c02b1f",
"hello",
"a8fff4739-5f85-452d-8955-b0b0ace74bf7",
"8fff4739-5f85-452d-8955-b0b0ace74bf7a"
};
Pattern p = Pattern.compile("^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$");
for (String input: uuids) {
System.out.print(input + " ");
if (p.matcher(input).matches()) {
System.out.println("matches");
} else {
System.out.println("does not match");
}
}
}
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.