regex - How to search for a special character in java string? -
i having problem searching special character "(".
got java.util.regex.patternsyntaxexception exception has occurred
.
might have "(" being treated special character. not pattern expression. can me search escape character?
// need split string @ "(" string mystring = "room temperature (c)"; string splitlist[] = mystring.split ("("); // got exception // tried got compile error string splitlist[] = mystring.split ("\(");
the reason got exception first time because split()
takes regular expression argument, , (
has special meaning there, suggest. avoid this, need escape using \
, tried.
what missed, need escape backslashes \
in java, meaning need total of two:
string splitlist[] = mystring.split ("\\(");
Comments
Post a Comment