An example unique identifier for example is:
"67a9854c-f63c-ef4a-0908-001fa4ff6512"
What is the regex to match this string?
An example unique identifier for example is:
"67a9854c-f63c-ef4a-0908-001fa4ff6512"
What is the regex to match this string?
Making some simple assumptions about the format of your identifier, I came up with "((?:\w){8}-(?:\w){4}-(?:\w){4}-(?:\w){4}-(?:\w){12})"
import java.util.regex.Matcher;
import java.util.regex.Pattern;
final String regex = "((?:\\w){8}-(?:\\w){4}-(?:\\w){4}-(?:\\w){4}-(?:\\w){12})";
final String string = "67a9854c-f63c-ef4a-0908-001fa4ff6512";
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));
}
}
Code generated using the excellent Regex101. I'd definitely recommend playing around with that next time, as it's very user-friendly.