Removes the first substring of the text string that matches the given regular expression.
This method is a
null safe equivalent to:
-
text.replaceFirst(regex, StringUtils.EMPTY)
-
Pattern.compile(regex).matcher(text).replaceFirst(StringUtils.EMPTY)
A
null reference passed to this method is a no-op.
The
Pattern#DOTALL option is NOT automatically added.
To use the DOTALL option prepend "(?s)"
to the regex.
DOTALL is also known as single-line mode in Perl.
StringUtils.removeFirst(null, *) = null
StringUtils.removeFirst("any", (String) null) = "any"
StringUtils.removeFirst("any", "") = "any"
StringUtils.removeFirst("any", ".*") = ""
StringUtils.removeFirst("any", ".+") = ""
StringUtils.removeFirst("abc", ".?") = "bc"
StringUtils.removeFirst("A<__>\n<__>B", "<.*>") = "A\n<__>B"
StringUtils.removeFirst("A<__>\n<__>B", "(?s)<.*>") = "AB"
StringUtils.removeFirst("ABCabc123", "[a-z]") = "ABCbc123"
StringUtils.removeFirst("ABCabc123abc", "[a-z]+") = "ABC123abc"