date - Regex - "captured group equals" in a condition -
i writing regex capture various date formats. maintain short , flexible, wanted pack possible combinations of months, days , years separate groups. let`s assume have 2 dates this:
01.01. - 31.12.2013
jan - dec 2013
now, want accomplish write regex capture both dates above ones. that's easy. want exclude dates e.g. those:
01.01. - 31 dec 2013
in other words, whenever months mixed, don't want dates. also, if first date doesn't have day, don't want day captured in sec 1 either.
i wanted build conditional captures sec date's appropriate fields, based on found in first 1 (so, e.g. if first date has alpha month, alpha month in sec one, ignore numeric). regex looks 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)\d\d|[012][0-9]$)
this background, question is, is possible check captured grouping equal , build capturing status based on that? found similar topic on stack overflow (can't find referenec, unfortunately), when implement it, stops capturing proper dates (e.g. 01.01. - 31.12.2013). part:
(?<secondmonth>((?<firstmonth>)(?<=0[1-9]|1[012]|[1-9]))(0[1-9]|1[012]|[1-9])|[\p{l}]{3,})
regex date
No comments:
Post a Comment