in reply to A tidier regex ?

What's the goal of the regex, validation, finding a match or extracting data from a line?

For extraction, the following should do:

/\b((?:CDC|DDCSMR|DDCRMR)\w*)/

For matching, it simplifies to

/\b(?:CDC|DDCSMR|DDCRMR)/

Replies are listed 'Best First'.
Re^2: A tidier regex ?
by Anonymous Monk on Sep 14, 2010 at 14:18 UTC
    It's for validation. These don't cater for the (underscores). These answers are opening up insight into Perl... I never realised it was so powerful.
      If you are validating, you should also anchor your regex to start and end of the string (and maybe allow leading and trailing whitespace).
      Perl 6 - links to (nearly) everything that is Perl 6.
      \w does match underscore.
        It allows me to put CDC_ABC as a valid option, which I wish to reject. When I was looking for CDC_ABC_ABC for example.