java - PatternSyntaxException when splitting string at "*" character -
every time try split string "hello*world"
using s.split("*");
patternsyntaxexception.
i have tried using s.split("\*");
gives me error. im sure simple.
how stop this?
the split
method takes regular expression argument, not normal string. *
has special meaning in regular expressions. if want split on literal *
, have escape backslash. backslash escape character in java string literals, have escape backslash using 2 backslashes:
s.split("\\*")
Comments
Post a Comment