I’m trying to figure out a way to remove all text in a string before match in Regex. I’m coding this in C#.
For example, if the string is “hello, test matching”, and the pattern is “test”, I would like the final result to be “test matching” (ie remove everything before test).
Any thoughts? Thanks!
EDIT: I probably should have been a bit more specific in my example after reading your responses (and thanks for them). I like the lookahead method, but I oversimplified my example. To make things more difficult, usually the strings look like:
“hello, test matching test everythingAfter”
So if I use the pattern “test”, it will catch the first one. What my goal is, is to replace all text after the second match. Ie: result in “test everythingAfter”…. Sorry about that.
*Updated, using matchcollection