Replaces the first substring of this string that matches the given regular expression with the given replacement.
An invocation of this method of the form
str .replaceFirst(regex , repl )
yields exactly the same result as the expression
java.util.regex.Pattern.compile(regex).matcher(str).replaceFirst(repl)
Note that backslashes ( \) and dollar signs ( $) in the
replacement string may cause the results to be different than if it were
being treated as a literal replacement string; see
java.util.regex.Matcher.replaceFirst.
Use java.util.regex.Matcher.quoteReplacement to suppress the special
meaning of these characters, if desired.
regex
| the regular expression to which this string is to be matched | |
replacement
| the string to be substituted for the first match |
String
PatternSyntaxException
| if the regular expression's syntax is invalid |
java.util.regex.Pattern
@spec JSR-51
Diagram: String