in reply to Recognizing 3 and 4 digit number

my $digits_4 = qr{ (?<=\ ) \d{4} \b }xms; my $digits_3 = qr{ (?<=\ ) \d{3} \b }xms;

Replies are listed 'Best First'.
Re^2: Recognizing 3 and 4 digit number
by htmanning (Friar) on Jan 02, 2017 at 02:20 UTC
    Okay, this worked BUT I just realized I cannot rely on a space to signal a valid number. Sometimes the number starts the text field so there is no space. I'm trying to recognize only those numbers that aren't followed or proceeded by a slash, dash, etc., that would indicate a phone number or date.
      my $digits_4 = qr{ (?<![\/-\ \w]) \d{4} (?![\/-\ \w]) }xms;

      untested...

        This one returns the following error:
        Invalid [] range "\\/-\\ " in regex; marked by <-- HERE in m/ (?<![\\/ +-\\ <-- HERE \\w]) \\d{4} (?![\\/-\\ \\w]) /
        I'm not really sure what is wrong.