regex - Split string by keeping "-" in words while eliminating it in other places in Java -
i want split string str = "hello, ,, one-word. yes - no: yea?" 
string[] parts = [hello, one-word, yes, no, yea] so far, have used str.split("(\\p{punct}*\\s)+")) gives parts = [hello, one, word, yes, no, yea], , str.split("[\\p{punct}&&[^-]]*\\s")) gives parts = [hello, one, -, word, yes, -, no, yea].
how split str, keeping -s , _s in words eliminating them , other regex in other places? want eliminate cases of multiple punctuation , white space, such .,    , ,.
Comments
Post a Comment