1

I am trying to translate a regex from Python to C#, but i am having some problems as i keep getting the error Unrecognized grouping construct.

^(?:\[(?P<release_group>.+?)\][ ._-]*)
(?P<series_name>.+?)[ ._-]+
(?P<ep_ab_num>\d{1,3})
(-(?P<extra_ab_ep_num>\d{1,3}))?[ ._-]+?
(?:v(?P<version>[0-9]))?
(?:[\w\.]*)
(?:(?:(?:[\[\(])(?P<extra_info>\d{3,4}[xp]?\d{0,4}[\.\w\s-]*)(?:[\]\)]))|(?:\d{3,4}[xp]))
(?:[ ._]?\[(?P<crc>\w+)\])?
.*?

What is giving me the error Unrecognized grouping construct in this regex?

Androme
  • 2,263
  • 4
  • 36
  • 77
  • 1
    Remove the `P`s from `(?P – OGHaza Dec 03 '13 at 15:53
  • 1
    p.s. you've got loads of unnecessary non-capturing groups (I count 5). Avoiding wrapping something in brackets is exactly the same as putting something in a non-capturing group - but a lot less messy! – OGHaza Dec 03 '13 at 16:05

1 Answers1

5

(?P<groupname>...) becomes (?<groupname>...) in .NET regexes. Just remove the P. Same semantics.

  • This answer has been added to the [Stack Overflow Regular Expression FAQ](http://stackoverflow.com/a/22944075/2736496), under "Groups". – aliteralmind Apr 10 '14 at 00:28
  • 1
    Are these differences documented somewhere? It seems that `(?R)` also doesn't work in .NET... – Rudey Aug 11 '14 at 08:15