Regex + Remove all text before match

后端 未结 3 1092
情书的邮戳
情书的邮戳 2020-12-19 06:05

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\

3条回答
  •  囚心锁ツ
    2020-12-19 06:40

    You can use positive lookahead to match a string but not capture it:

    (?=test)
    

    So you want to capture the stuff before the last occurrence of test:

    ^.*(?=test)
    

    If you want to make it so that it is the first occurrence of test, use lazy matching:

    ^.*?(?=test)
    

提交回复
热议问题