I have on input hex four byte values separated by : (something like aabbccdd:ffffffff:aaccbbff ). How to construct regex in Java which is going to give answer if input is in correct format or not ?
3 Answers
How about this?
String value = "aabbccdd:ffffffff:aaccbbff";
boolean match = value.matches("\\p{XDigit}{8}(:\\p{XDigit}{8})*");
// ...
The \p{XDigit} equals to [0-9a-fA-F] by the way. See also the java.util.regex.Pattern javadoc.
1 Comment
dhblah
"\\p{XDigit}{8}(?::\\p{XDigit}{8})*" would be better - no unnecessary group capturing