in reply to regexp problem
That only prints "NO MATCH" on the last line of input, and to fix that, you just need one more "?" in the regex:while (<DATA>) { if ( /\d{4}-?(\d{3})\s{0,}?(\d\d:\d\d:\d\d)?/ ) { print "Match: $_" ; } else { print "NO MATCH: $_"; } } __DATA__ 2005-100 10:12:01 2005100 10:12:01 2005-100 2005100 2005
/\d{4}-?(\d{3})?\s{0,}?(\d\d:\d\d:\d\d)?/ # ^--here
(updated code to fix indenting)
|
|---|