EDITUtilitarian@busybox ~$cat tmp/tmp.pl #!/usr/bin/perl use strict; use warnings; my $prefix='DOC_'; for (<DATA>){ chomp(my $line=$_); print "$line\n" if ($line =~ /^$prefix[0-9]{3}(_|-)[0-9]{3}$/); } __DATA__ DOC_001_123 DOC_002_214 DOC_001-548 DOC_001-987 Utilitarian@busybox ~$perl tmp/tmp.pl DOC_001_123 DOC_002_214 DOC_001-548
bart below is correct, to constrain the matches to hyphens the regex above should have read /^$prefix[0-9]{3}-[0-9]{3}$/
In reply to Re: Regex MATCH
by Utilitarian
in thread Regex MATCH
by stallion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |