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.
if want remove [, ] also, need include \\[, \\] inside character class.
string.replaceall("[/\\\\|*^`\\[\\]]", "");
Comments
Post a Comment