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

hello some body tell me how to match this type of statement start with either : numbers|characters then /pin atlast only 5 digits to follow /pin thanks Jack

Replies are listed 'Best First'.
Re: Pattern matching of the type?
by jynx (Priest) on Dec 12, 2001 at 13:00 UTC
    some assumptions first:

    1) you want at least one number or digit first
    2) you want the phrase "/pin"
    3) you don't want the phrase "atlast"

    The pattern match would be:

    m- # match ^(\w|\d)+ # at least one digit or number at the start of a string /pin # followed by the string "/pin" \d{5} # followed by 5 digits -x # ignore whitespace (and comments)
    This uses the prefix 'm' so that i can use different pattern match delimiters, in this case the dash. This way i don't have to escape the slash in '/pin', either in the match or in the comments :) This snippet doesn't capture correctly at all, but it should match the pattern i'm assuming you want. Maybe you can be a bit more specific?

    jynx

Re: Pattern matching of the type?
by Anonymous Monk on Dec 12, 2001 at 15:07 UTC
    thanks for your help I already done it via this /\/pin-\d{5}\Z/ regards
Re: Pattern matching of the type?
by Anonymous Monk on Dec 12, 2001 at 13:22 UTC
    HOW to restrict the statement to endup with 5 digits .not greater than 5 digits or nor less than 5 digits. i mean that 501-77-1245342/pin-67543

      You probably need to put the eol meta character at the end of your regex, something like this:

      m/ \d{5} # exactly five digits $ # end of line /x; # allow comments and whitespace

      -- Hofmator