in reply to Re: Regular Expression Question
in thread Regular Expression Question

print "$1\n" if /^(\w+[\w,]+\w+)$/ && !/,,/;

So, if I wanted to check for more than 2 consecutive commas (I should have mentioned that in the original post) I would do the following:

print "$1\n" if /^(\w+[\w,]+\w+)$/ && !/,{2,}/;

Replies are listed 'Best First'.
Re: Re: Re: Regular Expression Question
by kesterkester (Hermit) on Dec 04, 2003 at 21:35 UTC
    Either would work-- !/,,/ exludes strings containing 2 consecutive commas, and !/,{2,}/ excludes strings containing 2-or-more consecutive commas, which amounts to pretty much the same thing for what you want, if I've understood you correctly.
      Oop, sorry-- misread your question. If you wanted to check for more than 2 commas, you'd want to use either:
      /(\w+[\w,]+\w+)/ && !/,,,/

      or this:

      if /^(\w+[\w,]+\w+)$/ && !/,{3,}/;