The answer should be improved to explain why his regex need improvement and give readers an understanding of what the proposed regex is doing.I think the pattern that is shown for validating the MAC address should contain two groups of "0-f" values, that is, "^([a-f A-F0-9][a-f A-F0-9][:-])[a-f A-F0-9][a-f A-F0-9][:-]$".As an additional example, see the "almost RFC 822 compatible regex" in this answer.
)[a-f A-F0-9]$"); private static boolean is Valid Mac Address(String mac) .
If you want to avoid that, you can either get more clever than I with making it match the same character in each place, or just split the two patterns into one for each possible separator.
I liked petdance's solution ( ), but didn't use it because in my application I only wanted to allow ':' as the separator.
Thanks to the helpful CB people who assisted me with this: blakem, demerphq, davorg & Petruchio.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible 3) Any sufficiently advanced technology is indistinguishable from magic. Might be something there of interest to you (in addition to good answers already provided above).
cheers, Don striving toward Perl Adept tidies things up and makes it obvious what input is required, which helps document the code.Making it more restrictive than that can often be a risk of invalidating some valid e-mails. :[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f] | \[\x01-\x09\x0b\x0c\x0e-\x7f])*") @ (? You'd be surprised at some examples of valid e-mail addresses. Monks, Does anyone have a regex that will successfully match a MAC address that is better than the following?I'd like to be able to match the : or the 00-00-00-00-00-00 notation. The bummer with what you have there, besides being long, is that it matches stuff if you've got the colons and the dashes intermingled in the same string, which is probably NOT what you want. Petdance, Good catch on the intermixed colons and dashes.However, this really isn't an answer to the OP, since it only handles the "standard" MAC address format (nn:nn:nn:nn:nn:nn using colons or hyphens).private static Pattern pattern Mac Pairs = Pattern.compile("^([a-f A-F0-9][:\.-]?