RegEx - Match using symbols but don't replace them
c#, regex
Solution
So what you want to do is replace matches not followed by a `.` or a `+`? Use a lookahead:
@"Tests(?![.+])"
Problem
I would like to use a symbols in a RegEx pattern to find matches, but I don't want them replaced. This is for class and namespace manipulation in C#. For example: `MyNamespaceLib.EntityDataModelTests.TestsMyClassTests+MyInnerClassTests` must be replaced as: `MyNamespaceLib.EntityDataModel.TestsMyClass+MyInnerClass` (Note, only "Tests" is replace when it appears at the end of the namespace part, and not when it's part of the class/namespace name) I've managed to get the first part right in finding the matches, but I'm battling to keep the symbols in the replaced match. So far I have: `var input = "MyNamespaceLib.EntityDataModelTests.TestsMyClassTests+MyInnerClassTests";` `var output = Regex.Replace(input, "Tests[.+]|$", "");` I've tried using a non-capturing group, but I suspect it's not meant for the way I'm trying to use it. Thanks!