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?

[407 byte] By [microsmarta] at [2007-11-27 11:29:25]
# 1

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

TuringPesta at 2007-7-29 16:27:47 > top of Java-index,Java Essentials,New To Java...
# 2

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

microsmarta at 2007-7-29 16:27:47 > top of Java-index,Java Essentials,New To Java...
# 3

why it doesn't work and how to fix it?

microsmarta at 2007-7-29 16:27:47 > top of Java-index,Java Essentials,New To Java...
# 4

Try this: Pattern p4 = Pattern.compile("\\p{XDigit}{2}(?:[:-]\\p{XDigit}{2}){5}");

uncle_alicea at 2007-7-29 16:27:47 > top of Java-index,Java Essentials,New To Java...
# 5

thanks uncle_alice it works

but i didn't understand the code well

microsmarta at 2007-7-29 16:27:47 > top of Java-index,Java Essentials,New To Java...
# 6

> 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...

prometheuzza at 2007-7-29 16:27:47 > top of Java-index,Java Essentials,New To Java...
# 7

> Hope I got my terminology correct...

Couldn't have said it better myself.

uncle_alicea at 2007-7-29 16:27:47 > top of Java-index,Java Essentials,New To Java...