regex - java remove certain special characters -


sorry, might duplicated post i'm not understand how regex works. had referred others post yet still confuse. trying remove special characters when import file excel. appreciated.

below example data excel:

string test = "hello~i!am@b#c(d)an`d|opq/hmm\yes^123,.&*$"  test = test.replaceall("[^-a-za-z0-9", " ");  // not completed regex 

i have no idea how write full regex replace these characters ` ^ \ / | * empty string

you don't need put ^ @ start of char class, since it's special class in regex called negated character class.

string.replaceall("[/\\\\|*^`]", ""); 

in java regex, need use 4 backslashes match literal backslash character.

ideone

if want remove [, ] also, need include \\[, \\] inside character class.

string.replaceall("[/\\\\|*^`\\[\\]]", ""); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -