Reputation: 21003
I have a file that I want to get a specific date from. There are numerous dates in the file, but the one I am looking for is looks something like this:
Blahblah blah blah blahblahblah
07 October 2013
Private & Confidential
So I am trying to match a date which is followed by Private & Confidential
but I am not looking the Private & Confidential
to be in the capture. So I need the actual capture to be 07 October 2013
. The regex I have used is below:
(\d{2})(\/|-|\s*)?(January|February|March|April|May|June|July|August|September|October|November|December)(\/|-|\s*)?(\d{4})\s*(?:Private & Confidential)
I have been using ?:
to match but not capture the Private & Confidential
but I am not sure whether this is even the correct use. Does anyone have any ideas?
Upvotes: 0
Views: 81
Reputation: 10427
You should use a lookahead (?=...)
, also no need to capture the separators. :
(\d{2})(?:\/|-|\s*)?(January|February|March|April|May|June|July|August|September|October|November|December)(?:\/|-|\s*)?(\d{4})\s*(?=Private & Confidential)
Upvotes: 1