regex to remove all text before a character

前端 未结 6 1041
孤独总比滥情好
孤独总比滥情好 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:29

    ^[^_]*_
    

    will match all text up to the first underscore. Replace that with the empty string.

    For example, in C#:

    resultString = Regex.Replace(subjectString, 
        @"^   # Match start of string
        [^_]* # Match 0 or more characters except underscore
        _     # Match the underscore", "", RegexOptions.IgnorePatternWhitespace);
    

    For learning regexes, take a look at http://www.regular-expressions.info

提交回复
热议问题