c# – Regex Pattern Unable to Get Any Match

Firstly, I apologies on my minimal knowledge on Regex.

I have the following Regex pattern. However, I can’t get it to match with any input string.

1. Regex_In_SQL

"CRM service call returned an error: {error:{code:(.*),message:(.*)}}"

2. Input_String

"CRM Service call returned an error: {error:{code:ERROR_CODE,message:ERROR_MESSAGE}}";

Because of double quotes ", regex will contain escape \ after being fetched from SQL.

3. Regex_Retrieved_From_SQL

"CRM service call returned an error: {\"error\":{\"code\":\"(.*)\",\"message\":\"(.*)\"}}"

The matching is between Input_String and Regex_Retrieved_From_SQL.

Regex.Match(Input_String, Regex_Retrieved_From_SQL); //Always return no match

In this case, is it due to the incorrect regex pattern stored in SQL that causes no matches to any string after it is retrieved? *(as it contain escapes or double quotes)

I appreciate any corrective actions I should take against my Regex pattern, or my Input String.

Thank you.

Read more here: Source link