http://www.perlmonks.org?node_id=11132751


in reply to Need a regular expression to check the first digit

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11132725 use warnings; while( <DATA> ) { print /(?<!\d)5\d{8}(?!\d)/ ? ' ' : 'not', " found in : ", $_; } __DATA__ for me. "503009496" and i w for me. "603055496" and i w (6) for me. "703509496" and i w (7) for me. "53009496" and i w (too short) for me. "5093009496" and i w (too long) for me. "503009496" and i w

Outputs:

found in : for me. "503009496" and i w not found in : for me. "603055496" and i w (6) not found in : for me. "703509496" and i w (7) not found in : for me. "53009496" and i w (too short) not found in : for me. "5093009496" and i w (too long) found in : for me. "503009496" and i w