MrSnrub has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on need help with a Perl regular expression

Replies are listed 'Best First'.
Re: need help with a Perl regular expression
by toolic (Bishop) on Jul 16, 2014 at 15:35 UTC
    Read perlretut, then post some code if you have questions.
Re: need help with a Perl regular expression
by davido (Cardinal) on Jul 16, 2014 at 16:33 UTC

    /\d{2}-\d?\d{4}/
    • \d matches a digit.
    • {...} is a quantifier allowing you to specify an exact number of times its atom must match, or a range of legal number of times.
    • - is treated as a literal hyphen in this case.
    • ? as a quantifier specifies zero or one times.

    It could probably be simplified to:

    m/\d\d-\d{4,5}/

    ...since there's no real difference in this case between four digits with an optional leading extra digit, and four digits with an optional trailing extra digit.


    Dave

Re: need help with a Perl regular expression
by Anonymous Monk on Jul 17, 2014 at 03:25 UTC
Re: need help with a Perl regular expression
by bulrush (Scribe) on Jul 17, 2014 at 12:04 UTC