in reply to grep only lines having matched pattern
Both suggestions propose to check for a space to follow the date, but that will work well in this example, but will fail for dates that are located at the end of the line.
As you posted your data explicitely, that won't be a problem, but maybe looking at the criterium a bit more defensive, you can also say: match a date *not* followed by any of -, digit, letter or underscore (identifier characters).
my @lines = grep { m/ \b (?: 0[1-9] | 1[0-2] ) - (?: 0[1-9] | [12][0-9 +] | 3[01] ) - [0-9]{4} ) (?! [-\w] ) /x } @data;
And your input data is horrific: MM-DD-YYYY ... YYYY/MM/DD. How on earth does someone come up with a mixed format like that? (/me is all for a global ban on M/D/Y and Y/D/M format)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: grep only lines having matched pattern
by Marshall (Canon) on Apr 01, 2021 at 21:34 UTC | |
by Tux (Canon) on Apr 02, 2021 at 07:43 UTC |