"captured group equals" in a condition

I am writing a regex to capture various date formats. To keep it short and flexible, I wanted to pack all the possible combinations of months, days and years into separate groups. Let`s assume I have two dates like this:

01.01. - 31.12.2013

jan - dec 2013

Now, what I want to achieve is to write a regex that would capture both dates like the above ones. that's easy. but I also want to exclude dates like eg those:

01.01. - 31 dec 2013

In other words, whenever the months are mixed, I don't want those dates. Also, if the first date doesn't have a day, I don't want that day to be captured in the second one either.

I wanted to build a conditional which captures only the second date's appropriate fields, based on what is found in the first one (so, eg if the first date has an alpha month, look only for an alpha month in the second one, ignore numeric). My regex looks like this:

(?<firstDay>0[1-9]|[12][0-9]|3[01]|[1-9])[-/s.](?<firstMonth>0[1-9]|1[012]|[p{L}]{3,}|[1-9])s*[-s/.]*s*(?<secondDay>0[1-9]|[12][0-9]|3[01]|[1-9])[-s/.]*(?<secondMonth>((?<firstMonth>)(?<=0[1-9]|1[012]|[1-9]))(0[1-9]|1[012]|[1-9])|[p{L}]{3,})[-s/.]*(?<year>(19|20)dd|[012][0-9]$)

This is all background, but what my question is, is it possible to check what the captured group is equal to and build a capturing condition based on that? I found some similar topic on Stack Overflow (can't find it now to referenec, unfortunately), but when I implement it, it stops capturing some proper dates (eg 01.01. - 31.12.2013). This is that part:

(?<secondMonth>((?<firstMonth>)(?<=0[1-9]|1[012]|[1-9]))(0[1-9]|1[012]|[1-9])|[p{L}]{3,})
链接地址: http://www.djcxy.com/p/74786.html

上一篇: 在Java正则表达式中对Matcher组感到困惑

下一篇: 在一个条件下“被捕获的组等于”