Regex to remove all text before a character

regex

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 to learn to write regex would be great too. Most places I check are hard to learn from.

Best Answer

^[^_]*_

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