Regex including what is supposed to be non-capturing group in result

前端 未结 3 1342
耶瑟儿~
耶瑟儿~ 2020-12-12 04:35

I have the following simple test where i\'m trying to get the Regex pattern such that it yanks the executable name without the \".exe\" suffix.
 
It appears my n

3条回答
  •  不思量自难忘°
    2020-12-12 04:58

    It would match the non capturing group but won't capture it, so if you want the non captured part you should access the capture group instead of the whole match

    you can access groups in

    var asmName = Regex.Match(testEcl, @"([^\\]+)(?:\.exe)", RegexOptions.IgnoreCase);
    asmName.Groups[1].Value
    

    the demo for the regex can be found here

提交回复
热议问题