> I'm trying to debug my expression that matches an alphanumeric with any
> number of dashes (including none), except at the ends and obviously
> disallowing two or more consecutive dashes.
>
> Here it is: /\w+(-?\w+)*/
Looks fine. You probably want to anchor it, otherwise it should give
true for any string containing a match for \w. Also, the "?" is not
necessary:
/^\w+(-\w+)*/
> "0123-412-8370" false (should've been "true")
What are you doing? Because it gives true for me.
> "-ABC123" false
Should be true for the RegExp you gave.
> "00230-" false
Ditto.
> "ABC-123" false (should've been "true")
Is true.
> Would anyone lend a hand?
You are doing *something* wrong, because it works as expected for me.
Can you show us the page that fails, and say which browser you are
using?
/L

Signature
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
> Boy, regular expressions almost deserves its own topic!
Actually, several books in fact ;-)
> I'm trying to debug my expression that matches an alphanumeric with any
> number of dashes (including none), except at the ends and obviously
[quoted text clipped - 27 lines]
>
> Would anyone lend a hand? Thank you.
I tried your test cases with the following ugly test program
import java.util.regex.*;
public class t {
public static void main (String[] args){
if (args[0].matches(args[1]))
System.out.println("matches");
else
System.out.println("does not match");
}
}
Results were:
[sean@se2 tmp]$ java t 0123-412-8370 '\w+(-?\w+)*' matches
[sean@se2 tmp]$ java t 0-1 '\w+(-?\w+)*' matches
[sean@se2 tmp]$ java t ABC-123 '\w+(-?\w+)*' matches
Which according to your post match correctly as expected, so I guess your
regex is ok. Want to post
your code snippet for examination?

Signature
Sean
"It is one of the essential features of [incompetence] that the person
so afflicted is incapable of knowing that he is incompetent. To have
such knowledge would already be to remedy a good portion of the
offense." --W.I. Miller