java - Replace quotes which are not inside word -
i have long string containing several words.
some of these words have apostrophe eg . don't . words have apostrophe outside words example '''movieis great ''' or ''lot of apostrophe ''''' .
i want remove apostrophe not part of word.
for example in string = don't try ''''remove apostr inside'''' word'. output should don't try remove apostr inside word.
i wrote regex .*[^a-z]'[^a-z].* not getting desired output in java code. string s = "don't try ''''remove apostr inside'''' word'"; s = s.replace(".*[^a-z]'[^a-z].*", " ");
note .replace()
replaces literal strings , not allow regex search argument.
you may use regex match apostrophes not enclosed word boundaries:
string s = "don't try ''''remove apostr inside'''' word' 'żoł'"; s = s.replaceall("(?u)\\b'\\b|\\b'\\b|\\b'\\b", ""); system.out.println(s);
see online java demo
here, \b
word boundary, \b
position other word boundary , (?u)
makes \b
, \b
unicode aware.
Comments
Post a Comment