views:

956

answers:

2

Hi, I have this working definition:

IDENTIFIER   [a-zA-Z][a-zA-Z0-9]*

I don't want to keep repeating the [a-zA-Z] and [0-9], so I made two new definitions

DIGIT    [0-9]
VALID    [a-zA-Z]

How can I rewrite the IDENTIFIER rule to use the DIGIT and VALID definitions?

I don't know how to do the "second" match, I'm stuck here:

IDENTIFIER {VALID}[{VALID}{DIGIT}]* // This syntax is incorrect

Thanks.

Edit: The entire test program that I'm using: http://pastebin.com/f5b64183f.

A: 

I think this'll do it but I can't test it. do you have sample data?

(?:[a-zA-Z])+(?:[0-9])+

Keng
The first regex is working, but I want to simplify it.
Kknd
+3  A: 

It looks like you actually want:

IDENTIFIER {VALID}({VALID}|{DIGIT})*

[{VALID}{DIGIT}] resolves to [[A-Za-z][0-9]] which is not a legal construct.

Ben Doom
Excellent. You neatly got to the point, unlike me who took three attempts at it. So I've deleted my rather confusing answer. Sorry for no upvote, but I'm used all my votes up for today :(
David Arno
@David Arno: Feel free to come back tomorrow and bump my answer. :-)
Ben Doom
@Ben, suitably bumped :)
David Arno