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

Warning for useless use of regex quantifier modifiers?

Thread Next
Thomas Sibley
July 16, 2014 08:55
Warning for useless use of regex quantifier modifiers?
Message ID:

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:


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About