regex to remove all text before a character

前端 未结 6 1029
孤独总比滥情好
孤独总比滥情好 2020-12-13 06:46

Is there an easy way to remove all chars before a \"_\"? For example, change 3.04_somename.jpg to somename.jpg.

Any suggestions for where t

6条回答
  •  爱一瞬间的悲伤
    2020-12-13 07:20

    Variant of Tim's one, good only on some implementations of Regex: ^.*?_

    var subjectString = "3.04_somename.jpg";
    var resultString = Regex.Replace(subjectString,
        @"^   # Match start of string
        .*?   # Lazily match any character, trying to stop when the next condition becomes true
        _     # Match the underscore", "", RegexOptions.IgnorePatternWhitespace);
    

提交回复
热议问题