regex - java replaceAll and '+' match -



regex - java replaceAll and '+' match -

i have code setup remove spaces in between words of title

string formattedstring = unformattedstring.replaceall(" +"," ");

my understanding of type of regex match many spaces possible before stopping. however, strings coming out not changing in way. possible it's matching 1 space @ time, , replacing space? there replaceall method, since it's doing multiple matches, alter way type of match work here?

a improve approach might utilize "\\s+" match runs of possible whitespace characters.

edit

another approach might extract matches "\\b([a-za-z0-9]+)\\b" , bring together them using space allow remove except valid words , numbers.

if need preserve punctuation, utilize "(\\s+)" capture runs of non-whitespace characters.

java regex

Comments

Popular posts from this blog

c# - Move local mssql database to webhosted MYSQL -

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -