regex - Escape special character ^ in a regular expression in Java -
this question has answer here:
i want split string in java following format: "value^1" initial part, "value" in string.
i wanted use split instead of substring, tried this:
string.split("^")[0]
but unfortunately ^ special character , guess has escaped. tried split("\^") no luck.
anybody knows how achieve using split?
thanks!
escape escape: split("\\^")
. or split(pattern.quote("^"))
.
but since want first part of it, there's no need use split
:
int pos = string.indexof('^'); string firstpart = (pos != -1) ? string.substring(0, pos) : string;
Comments
Post a Comment