Why doesn't this line of code work? It's supposed to replace all the punctuations with nothing.
m = m.replace("[\\?\\.;:'\"]", "")
m will not change after executing this line in java even though it contains punctuations. Why?
asked Mar 24, 2013 at 3:16
DarrenVortex
1951 gold badge2 silver badges15 bronze badges
-
2Dasblinkenlight nailed it. As a side note, there's no need to escape a question mark or period inside a character class.phatfingers– phatfingers2013年03月24日 03:27:18 +00:00Commented Mar 24, 2013 at 3:27
1 Answer 1
This is because replace takes a String; you need to call replaceAll, which does take a regular expression.
answered Mar 24, 2013 at 3:18
Sergey Kalinichenko
729k85 gold badges1.2k silver badges1.6k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-java