我需要从URI中提取UUID,目前的成功率为50%,请有人能够友善地建议给我一个确切匹配的正则表达式吗?
public static final String SWAGGER_BASE_UUID_REGEX = ".*?(\\p{XDigit}{8}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{12})(.*)?";
public static final String abc="https://127.0.0.1:9443/api/am/store/v0.10/apis/058d2896-9a67-454c-95fc-8bec697d08c9/documents/058d2896-9a67-454c-9aac-8bec697d08c9";
public static void main(String[] args) {
Pattern pairRegex = Pattern.compile(SWAGGER_BASE_UUID_REGEX);
Matcher matcher = pairRegex.matcher(abc);
if (matcher.matches()) {
String a = matcher.group(1);
String b = matcher.group(2);
System.out.println(a+ " ===========> A" );
System.out.println(b+ " ===========> B" );
}
}
我目前得到的输出是:
058d2896-9a67-454c-95fc-8bec697d08c9 ===========> A
/documents/058d2896-9a67-454c-9aac-8bec697d08c9 ===========> B
现在我希望B的输出只是:
058d2896-9a67-454c-9aac-8bec697d08c9
任何帮助都将不胜感激!!!谢谢