capturing group not working in Regex

Using regex, I want to match the following strings:

January 25
Jan 25

I'm capturing month and date parts separately but want to return only the first 3 characters of month name if there's full month name, so I'm using non-capturing group (?:) for the characters "uary":

(?<M>(Jan(?:uary)?)) (?<D>dd)

Unfortunately, the group M always returns full month name; ie it captures the non-capturing group too.

I have already turned on ExplicitCapture flag. I've used both RegExBuilder and Rad Software's Regular Expression Designer to make sure it is not because of the tool.


Your capturing group should surround only Jan .

(?<M>Jan)(?:uary)? (?<D>d{1,2})

Your original expression is roughly equivalent to (?<M>January|Jan) (?<D>dd) . The non-capturing group does not mean that the match is removed from existing capturing groups. It means only that no new capturing group is created.


尝试:

(?<M>Jan)(?:uary)? (?<D>dd)
链接地址: http://www.djcxy.com/p/12974.html

上一篇: DFA正则表达式引擎可以处理原子组吗?

下一篇: 捕获不在Regex中工作的组