Reputation: 101
String string = "This is a example.just to verify.please help me.";
if(string.matches("(.*).(.*)"))
{
System.out.println(true);
String[] parts = string.split("\\r?\\n");
for(String part:parts){
System.out.println(part);
}
}
I want to split the string after every dot to the next line. can anyone help me in this. thanks in advance.
Upvotes: 0
Views: 134
Reputation: 174766
Use positive lookbehind. And also in matches function, you need to escape the dot like string.matches(".*\\..*")
, since dot is a regex special character which matches any character.
String[] parts = string.split("(?<=\\.)");
or
If you don't want to do a split after the last dot.
String[] parts = string.split("(?<=\\.)(?!$)");
Upvotes: 2
Reputation: 26077
use regex "\\."
public static void main(String[] args) {
String string = "This is a example.just to verify.please help me.";
if (string.matches("(.*).(.*)")) {
System.out.println(true);
String[] parts = string.split("\\.");
for (String part : parts) {
System.out.println(part);
}
}
}
output
true
This is a example
just to verify
please help me
Upvotes: 2