Makar Emelyanov Makar Emelyanov - 10 months ago 222
C# Question

C# Regex Exception - insufficient hexadecimal digits

I am trying to write some regex pattern code that will take out certain parts of a text by using groups. Here is the code:

private static string ParseSnippet(string ownitDirectory, string project)
Match m = Regex.Match("(" + project + "\\\\.*\\\\)", ownitDirectory, RegexOptions.IgnoreCase);
return m.Groups[1].Value;

The problem I am having is that the pattern I am using causes an exception to occur. This exception does not make any sense to me. I have tested the pattern in plenty of online testers but this did not help the problem.

Would anybody have any suggestions as to what I should do?


Forgot to mention that the exception is "Insufficient hexadecimal digits"

Answer Source

According to this page, it seems that the parameters for Regex.Match are inverted. Have you tried this?

Regex.Match(ownitDirectory, "(" + project + "\\\\.*\\\\)", RegexOptions.IgnoreCase);