-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Please add replaceAll(String regex, Function<String, String> replacer) method to java.lang.String class, example of use:
```java
String test = "Text with русским text";
System.out.println(test.replaceAll("([а-я]+)", matcher -> matcher.group().toLowerCase())); // Output: Text with РУССКИМ text
System.out.println(test.replaceAll("([а-яА-Я]+)", matcher -> "")); // Output: Text with text
String nums = "num1 число2 num3";
System.out.println(replaceAll(nums, "[\\w\\p{IsCyrillic}]+\\d", m -> {
boolean isRussian = m.matches(".*[а-яА-Я].*");
return isRussian ? "<РУС>" : "<ENG>";
})); // Output: "<ENG> <РУС> <ENG>"
```
Code of method:
```java
public static String replaceAll(String regex, Function<String, String> replacer) {
return Pattern.compile(regex).matcher(this).replaceAll(r -> replacer.apply(r.group()));
}
```
Please add replaceAll(String regex, Function<String, String> replacer) method to java.lang.String class, example of use:
```java
String test = "Text with русским text";
System.out.println(test.replaceAll("([а-я]+)", matcher -> matcher.group().toLowerCase())); // Output: Text with РУССКИМ text
System.out.println(test.replaceAll("([а-яА-Я]+)", matcher -> "")); // Output: Text with text
String nums = "num1 число2 num3";
System.out.println(replaceAll(nums, "[\\w\\p{IsCyrillic}]+\\d", m -> {
boolean isRussian = m.matches(".*[а-яА-Я].*");
return isRussian ? "<РУС>" : "<ENG>";
})); // Output: "<ENG> <РУС> <ENG>"
```
Code of method:
```java
public static String replaceAll(String regex, Function<String, String> replacer) {
return Pattern.compile(regex).matcher(this).replaceAll(r -> replacer.apply(r.group()));
}
```