Matcher.ReplaceAll Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ReplaceAll(IFunction) |
Replaces every subsequence of the input sequence that matches the pattern with the result of applying the given replacer function to the match result of this matcher corresponding to that subsequence. |
ReplaceAll(String) |
Replaces every subsequence of the input sequence that matches the pattern with the given replacement string. |
ReplaceAll(IFunction)
Replaces every subsequence of the input sequence that matches the pattern with the result of applying the given replacer function to the match result of this matcher corresponding to that subsequence.
[Android.Runtime.Register("replaceAll", "(Ljava/util/function/Function;)Ljava/lang/String;", "", ApiSince=34)]
public string ReplaceAll (Java.Util.Functions.IFunction replacer);
[<Android.Runtime.Register("replaceAll", "(Ljava/util/function/Function;)Ljava/lang/String;", "", ApiSince=34)>]
member this.ReplaceAll : Java.Util.Functions.IFunction -> string
Parameters
- replacer
- IFunction
The function to be applied to the match result of this matcher that returns a replacement string.
Returns
The string constructed by replacing each matching subsequence with the result of applying the replacer function to that matched subsequence, substituting captured subsequences as needed.
- Attributes
Remarks
Replaces every subsequence of the input sequence that matches the pattern with the result of applying the given replacer function to the match result of this matcher corresponding to that subsequence. Exceptions thrown by the function are relayed to the caller.
This method first resets this matcher. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any match are appended directly to the result string; each match is replaced in the result by the applying the replacer function that returns a replacement string. Each replacement string may contain references to captured subsequences as in the #appendReplacement appendReplacement
method.
Note that backslashes (\
) and dollar signs ($
) in a replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.
Given the regular expression dog
, the input "zzzdogzzzdogzzz"
, and the function mr -> mr.group().toUpperCase()
, an invocation of this method on a matcher for that expression would yield the string "zzzDOGzzzDOGzzz"
.
Invoking this method changes this matcher's state. If the matcher is to be used in further matching operations then it should first be reset.
The replacer function should not modify this matcher's state during replacement. This method will, on a best-effort basis, throw a java.util.ConcurrentModificationException
if such modification is detected.
The state of each match result passed to the replacer function is guaranteed to be constant only for the duration of the replacer function call and only if the replacer function does not modify this matcher's state.
Added in 9.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
ReplaceAll(String)
Replaces every subsequence of the input sequence that matches the pattern with the given replacement string.
[Android.Runtime.Register("replaceAll", "(Ljava/lang/String;)Ljava/lang/String;", "")]
public string ReplaceAll (string replacement);
[<Android.Runtime.Register("replaceAll", "(Ljava/lang/String;)Ljava/lang/String;", "")>]
member this.ReplaceAll : string -> string
Parameters
- replacement
- String
The replacement string
Returns
The string constructed by replacing each matching subsequence by the replacement string, substituting captured subsequences as needed
- Attributes
Remarks
Replaces every subsequence of the input sequence that matches the pattern with the given replacement string.
This method first resets this matcher. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any match are appended directly to the result string; each match is replaced in the result by the replacement string. The replacement string may contain references to captured subsequences as in the #appendReplacement appendReplacement
method.
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. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.
Given the regular expression a*b
, the input "aabfooaabfooabfoob"
, and the replacement string "-"
, an invocation of this method on a matcher for that expression would yield the string "-foo-foo-foo-"
.
Invoking this method changes this matcher's state. If the matcher is to be used in further matching operations then it should first be reset.
Java documentation for java.util.regex.Matcher.replaceAll(java.lang.String)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.