in reply to Re: simple regexp problem
in thread simple regexp problem

Ah shoot! While the advice in the above post is sound, the code won't work because "\w" includes "_"! Fix:
/^([a-zA-Z0-9+])(?:_(\w+))?$/

or

/^((?:(?!_)\w)+)(?:_(\w+))?$/

Replies are listed 'Best First'.
Re^3: simple regexp problem
by jeanluca (Deacon) on Dec 06, 2005 at 13:36 UTC
    This works too: /^(\w+?)(?:_(\w+))?$/ But why the last ? ? If I leave it off, it doesn't parse the string "AAAAAAA"

    Thanks
    Luca

      atom? (as opposed to atom??, atom*? and atom+?) means atom is optional. In other words, it provides the "optionally" in "you want AAAAAA optionally followed by _BBBBBB".