I am using this regex pattern (\[|)(\w\w \d*)(\; |\*|\s|]?, )((\"(\w)\"|\((.\w)\))|)(\]|)|(\[\w\w \d\]) to match the below string:
Hp 0; Ks 1; Ks 2
I have tested this pattern in https://regex101.com/, and everything works fine, complete string is matched Hp 0; Ks 1; Ks 2
. But the same pattern in Visual Studio (.Net Framework) match just Hp 0; Ks 1;.
Can anyone help me where is the problem ?
I have written this code in VS:
StringBuilder matchedSignalbegriff = new StringBuilder();
var pattern = "(\\[|)(\\w\\w \\d*)(\\; |\\*|\\s|]?, )((\"(\\w)\"|\\((.\\w)\\))|)(\\]|)|(\\[\\w\\w \\d\\])";
Regex rgx = new Regex(pattern);
foreach (Match match in rgx.Matches(stringToTest))
{
matchedSignalbegriff.Append(match);
}
@) when doing Regexes. Something likevar pattern = @"(\[|)(\w\wetc. In all likelihood, you have a misplaced escape character if it works in a tool and not in your codeRegex rgx = new Regex(@"(\[|)((\w\w \d*)((\; )?|\*|\s|]?, ))*((\""(\w)\""|\((.\w)\))|)(\]|)|(\[\w\w \d\])");