[Solved] C# regular expression engine does not work [closed]


EDIT: based on your edit the issue is that you’re using the parameters out of order. You need to switch the order and supply the input (string source to find a match in) then the pattern (what to match against).

In fact, this order is specified for you by the IntelliSense as depicted in this image:

Regex parameters ordering

It usually helps to match the naming suggested by the IntelliSense or refer to it to ensure the proper items are being passed in.


What is the character being used? Chances are you’re trying to use a character that is actually a metacharacter which holds special meaning in regex.

For example:

string result = Regex.Match("$500.00", "$").Value;

The above wouldn’t return anything since $ is a metacharacter that needs to be escaped:

string result1 = Regex.Match("$500.00", @"\$").Value;  // or
string result2 = Regex.Match("$500.00", "\\$").Value;  // or
string result3 = Regex.Match("$500.00", Regex.Escape("$")).Value;

For a list of common metacharacters that need to be escaped look at the Regex.Escape documentation.

5

solved C# regular expression engine does not work [closed]