0

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?

4

2 回答 2

2

使用前瞻

(?=\s*Private & Confidential)
于 2013-10-17T12:17:02.423 回答
1

您应该使用前瞻(?=...),也无需捕获分隔符。:

(\d{2})(?:\/|-|\s*)?(January|February|March|April|May|June|July|August|September|October|November|December)(?:\/|-|\s*)?(\d{4})\s*(?=Private & Confidential)

演示

于 2013-10-17T12:17:44.550 回答