Reputation: 9044
I have atext file that contains a lot of records like this:
05/11/04+11:10PM+117+04+0218735793+0'00+00:01'51+TR+
or
05/11/04+11:10PM+117+04+0218735793+0'00+00:01'51+TR+
(without INCOMING)
I want to validate these lines and invalidate all other lines(empty lines or comment lines and corrupted lines.
Thanks.
Upvotes: 0
Views: 314
Reputation: 50104
I wouldn't try to use a regex for all of it. For example, you have what looks like a date and a time in there, and a couple of other fields that could be times of some kind, which are tricky to do with regular expressions.
I'd handle this with
String.Split
on +
DateTime.TryParseExact
DateTime.TryParseExact
Upvotes: 3
Reputation: 120380
var regexPattern = @"^\d{2}/\d{2}/\d{2}\+\d{2}:\d{2}(?:AM|PM)\+\d{3}\+\d{2}" +
@"\+\d{10}\+\d'\d{2}\+\d{2}:\d{2}'\d{2}\+TR\+$"
Upvotes: 0
Reputation: 30273
^\d\d\/\d\d\/\d\d\+\d\d:\d\d[AP]M\+[\d+':]+\+TR\+$
^^^^^^^^
I "cheated" in the marked section because I'm not sure exactly what's staying the same, but from the rest of the expression I think you should get the idea.
Upvotes: 0