I have the below string
String srcString = "String1.String2.String3";
I want to split "srcString" on "."
Using srcString.split(".") is matching all the characters.
What is the regex to match a "." ?
I have the below string
String srcString = "String1.String2.String3";
I want to split "srcString" on "."
Using srcString.split(".") is matching all the characters.
What is the regex to match a "." ?
In regex dot is special character representing any character except line separator (to also make it match line separators use Pattern.DOTALL
flag).
Anyway, use split("\\.")
Explanation:
.
we can add \
before it so we end up with regex \.
\
is also special in string literal " "
we also need to escape it there, so to express \.
we need to write it as "\\."
.Use split("\\.")
as . (dot) is special character so use \\
before .(dot)
You could also call the function org.apache.commons.lang.StringUtils.split(String, char)
of the library commons-lang
[http://commons.apache.org/lang/][1]