regular expression question about punctuation
hello there
i'm trying to check a line in the command line to find the mac address
so i need a little help in the pattern to complie
here is what i've tried
Pattern p4=Pattern.compile("\\d|\\w{0,}\\p{Punct}\\d|\\w{0,}\\p{Punct}\\d|\\w{0,}\\p{Punct}\\d|\\w{0,}\\p{Punct}\\d|\\w{0,}\\p{Punct}\\d|\\w{0,}");
but it didn't work so what 's wrong?
It might be better to split the input on a non-hex digit.
String[] tokens = macInput.split("[^0-9a-f]");
Your regex seems unneccessarily complicated.
String macInput = "01.23.45.67.89.ab"
Pattern.compile("[0-9a-f]{2}[:\.]") x6
it gaves me 3 errors in the complie line
String[]s=sb.toString().split("[^0-9a-f]");
Pattern p4=Pattern.compile("[0-9a-f]{2}[:\.]") x6 ;
illegal escape character
';' expected
not a statement
> thanks uncle_alice it works
> but i didn't understand the code well
\\p{XDigit}{2}exactly two hexadecimal digits
(?:the following as a non-capturing group
[:-]followed by a ':' or a '-'
\\p{XDigit}{2}followed by exactly two hexadecimal digits
){5}the previous (group) exactly five times
Hope I got my terminology correct...