regex - Trimming whitespace from a String in Java -


i realize there quite number of questions on have yet find solution suitable situation. know of string.trim() , has no effect. after researching online , uncovering world of hate string.trim() realize whitespace character trying remove must out of range .trim() caters for.

i using regex, not understand, strip string of special characters excluding '=' , ',' , whitespace except if after ','.

however, want remove whitespace string. ideas of how edit regex using accomplish appreciated. again, want '=' , ',' along digits , letters remain. whitespace , other special characters should removed.

here's code far:

if (argstobefiltered != null) {             // remove whitespace , chars apart = , ,             string filteredargs = argstobefiltered.replaceall(                     "[^=,\\da-za-z\\s]|(?<!,)\\s", "");             return filteredargs; } 

time learn regular expression!

see pattern , various regular expression tutorials such lesson: regular expressions.

[^=,\\da-za-z\\s] 

that part says match not (^) characters: =, ,, digits (\d), a-z (a-z) or whitespace (\s). however, want match spaces (as there no second after-comma part match them). so:

argstobefiltered.replaceall("[^=,\\da-za-z]", ""); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -