develooper Front page | perl.perl5.porters | Postings from July 2014

Warning for useless use of regex quantifier modifiers?

Thread Next
From:
Thomas Sibley
Date:
July 16, 2014 08:55
Subject:
Warning for useless use of regex quantifier modifiers?
Message ID:
20140715220339.GF14254@orac
Hi,

I wonder if there'd be support for issuing a warning when regex syntax
like \d{2}? is used?  The ? is a useless minimal modifier when used with
{n}, though it of course has a use with {n,m} and {n,}.  Presumably the
possessive equivalent {n}+ would also warn.

I was momentarily tripped up by it earlier today, expecting it to behave
like (\d{2})? instead.  The documentation is clear and the behaviour
makes sense after more consideration, but a warning might be useful to
catch this "useless use" of a quantifier modifier.  Though there are
some false positives in this CPAN grep, it seems I'm not entirely alone
in my mistake: http://grep.cpan.me/?q=%5C%7B%5Cd%2B%5C%7D%5C%3F

Cheers,
Thomas

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About