javaregexstringstring-utils

Regular expression to remove unwanted characters from the String


I have a requirement where I need to remove unwanted characters for String in java. For example, Input String is

Income ......................4,456
liability........................56,445.99

I want the output as

Income 4,456
liability 56,445.99

What is the best approach to write this in java. I am parsing large documents for this hence it should be performance optimized.


Solution

  • You can do this replace with this line of code:

    System.out.println("asdfadf ..........34,4234.34".replaceAll("[ ]*\\.{2,}"," "));