This question already has an answer here:
I am having trouble converting this Regex pattern:
"\bGOTO\s+\K\S+"
into a Regex that can be used with C#.NET. The problem seems to be that \K cannot be used, but not being well versed in Regular Expressions, I don't know how I would go about fixing the problem. Any help would be appreciated.
An explicit conversion from \K
to c# would probably help alot with using it in other Regexes, too.
EDIT: The Perl reference table to c# didn't help me that much, as I could not find an explicit conversion from \K to something compatible with c#. I looked at what \G was, but that does not appear to be what I am looking for
</div>
\K
Sets the given position in the regex as the new "start" of the match. This means that nothing preceding the K will be captured in the overall match.
However, if you want to insert it into a string in C#, you need to add escaped character so the string would be recognized as a Regex pattern or use verbatim string. Also, in the .net framework, you need to add a group name for the \K<GroupName>
Here are snippets you could find useful:
Regular Regex:
\bGOTO\s+\k<TextHere>\S
Escaped Character:
\\bGOTO\\s+\\k<TextHere>\\S
Regex rgx = new Regex("\\bGOTO\\s+\\k<TextHere>\\S");
foreach (Match m in rgx.Matches("String to match"))
Console.WriteLine($"{m.Value} at -> {m.Index}");