in reply to Re: regex to match words and numbers
in thread regex to match words and numbers

next if $data =~ /^[\pL\pN.*]/; doesn't appear to accept anything of interest:

>perl -wMstrict -le "my @data = ( '1. for future assistance toss', '* You can also toss', 'Page 2, toss', '12345 keep this', '... keep this', ); ;; for my $datum (@data) { print qq{how about '$datum'?}; next if $datum =~ /^[\pL\pN.*]/; print qq{keep it}; } " how about '1. for future assistance toss'? how about '* You can also toss'? how about 'Page 2, toss'? how about '12345 keep this'? how about '... keep this'?

Replies are listed 'Best First'.
Re^3: regex to match words and numbers
by moritz (Cardinal) on Jun 08, 2011 at 19:45 UTC

    The way I understood the OP, the regex should reject all of the example lines, because all of them start with one of (dot, star, word, digit).

    That's what my regex does, and everything else (lines starting with a bang, slash, backslash, ...) is accepted.

    If that's not what doubledecker wants, he or she should clarify the original posting.

      3. Any line starting with digit and .

      I took this to mean "Any line starting with a digit that is immediately followed by a period". (And I wouldn't be surprised to find this really should be "starting with digits..." rather than "a digit...")

      2. Any line starting with a word

      This is the one that always gives me pause. The common assumption seems to be that the definition, regex or otherwise, of a 'word' is perfectly straightforward, but I can see too many variations to be comfortable with this.

      I need to get lines that start with numbers everything else should be rejected.