in reply to How to consolidate regex's?

If you don't mind accepting 23,,4,5,2789 too, this combo will work:

if ($val =~ /([\d,]*) views/) { $num_views= $1; $num_views=~s/,//g;

UPDATE: Thanks to GrandFather the 'fi' (which only the NSA knows about) was changed to 'if'

Replies are listed 'Best First'.
Re^2: How to consolidate regex's?
by ikegami (Patriarch) on Feb 05, 2010 at 07:30 UTC

    If you don't mind accepting 23,,4,5,2789 too

    The match op can be used to capture and it can be used to validate. It can't always do both at the same time, and even when it can, sometimes the smart thing to do is to not care about validation.

    As long as it does the right thing for proper inputs and it doesn't do anything overly bad for bad inputs, you're good.

    [ I forget that too often ]