About 28,700 results
Open links in new tab
  1. java - Difference between String replace() and replaceAll() - Stack ...

    May 31, 2012 · Agree, In Java 8 practically both methods are almost the same, for both appear the Pattern.compile(...) content/part in their implementations, seems replace is less complex about how to define/send the first argument. It does not require "\". Furthermore replace is available since Java 1.5 and replaceAll since 1.4 –

  2. How do I replace all occurrences of a string? - Stack Overflow

    Given a string: string = "Test abc test test abc test test test abc test test abc"; This seems to only remove the first occurrence of abc in the string above: string = string.replace('ab...

  3. string - java replaceAll () - Stack Overflow

    Jul 7, 2009 · What is the regular expression for replaceAll() function to replace "N/A" with "0" ? input : N/A output : 0

  4. Java Regex Replace with Capturing Group - Stack Overflow

    Thanks for the great answer, you snipped out the most useful part of that value multiplier example! This made it very clear to me! @mezzie Very good addition! Although it is present in the Java docs for java.util.regex.Matcher, for the folks who solely refer this …

  5. java - String replaceAll() vs. Matcher replaceAll() (Performance ...

    Jan 19, 2022 · An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression. Pattern.compile(regex).matcher(str).replaceAll(repl) Therefore, it can be expected the performance between invoking the String.replaceAll, and explicitly creating a Matcher and Pattern should be the same. Edit

  6. Regex expressions in Java, \\s vs. \\s+ - Stack Overflow

    Nov 16, 2019 · However x.replaceAll("\\s+", ""); will be more efficient way of trimming spaces (if string can have multiple contiguous spaces) because of potentially less no of replacements due the to fact that regex \\s+ matches 1 or more spaces at once and replaces them with empty string.

  7. java - How to use Pattern in String replaceAll - Stack Overflow

    Feb 10, 2014 · I used Pattern as parameter in replaceAll method, I want to remove all characters inside open and close bracket (include bracket characters) however only inside chars was remove, the bracket is still there. Below is my java code. String test = "This is my test ( inside the brackets ) and finish here"; String regex = "\\(.*\\)";

  8. regex - Java: Replace all ' in a string with - Stack Overflow

    Dec 13, 2013 · An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression. Pattern.compile(regex).matcher(str).replaceAll(repl) So lets take a look at Matcher.html#replaceAll(java.lang.String) documentation

  9. Java Replacing multiple different substring in a string at once (or …

    Rythm a java template engine now released with an new feature called String interpolation mode which allows you do something like: String result = Rythm.render("@name is inviting you", "Diana"); The above case shows you can pass argument to template by position.

  10. java - ReplaceAll with java8 lambda functions - Stack Overflow

    Java 9 and above. Java 9 introduced Matcher.replaceAll(Function) which basically implements the same thing as the functional version for Java 8 below.

Refresh