java scanner - how to split a mac address?
<p>The mac address string may be in format:</p>

<p>00:aa:bb:cc:dd:ee</p>

<p>or </p>

<p>00aabbccddee</p>

<p>I need a good way to retrieve the 6 parts. </p>

<p>Here my code:</p>

<pre><code>public class Mac
{
    public static void main(String[] args)
    {
        String mac = "00:aa:bb:cc:dd:ee"; /* 00aabbccddee */
        Scanner s = new Scanner(mac);
        s.useDelimiter(":?"); /* zero or one occurrence */                                                                                                                             
        String t = null;
        while ((t = s.next("[0-9a-f][0-9a-f]")) != null)
            System.out.println(t);
    }
}
</code></pre>

<p>It throws a exception:</p>

<pre><code>Exception in thread "main" java.util.InputMismatchException
        at java.util.Scanner.throwFor(Scanner.java:840)
        at java.util.Scanner.next(Scanner.java:1461)
        at java.util.Scanner.next(Scanner.java:1394)
        at Mac.main(Mac.java:11)
</code></pre>

<p>What's wrong with it?</p>
