Last active
May 20, 2020 03:07
-
-
Save S4WA/e61ec23a83ff132ce8a142e8e9128812 to your computer and use it in GitHub Desktop.
Make parse UUID from no hyphen string (Error: "java.lang.illegalargumentexception:java.lang.illegalargumentexception: Invalid UUID string")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static UUID parseUUID(String uuid) { | |
try { | |
return UUID.fromString(uuid); | |
} catch (IllegalArgumentException exception) { | |
return UUID.fromString(uuid.replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment