I'm trying to create a a regex that matches 2 or more spaces, or tabs, basically a combination of text.split(" ")
and text.split("\t")
. How do I create it?
My attempt: (but it doesn't work)
text.split(new RegExp("[ |\t]"))
Edit: This splits at spaces/tabs but I need to split at 2 spaces or more..
text.split("\\s+");
\s{2,}
You can try in this way...! \s{2,} means 2 or more
I got this idea from this replace post Regex to replace multiple spaces with a single space
Demo: http://jsbin.com/akubed/1/edit
I agree with @Will comment - Add Tab space also
\s{2,}|\t
String s="This is test";
String [] as=s.split("\\t{2,}");
for(int i=0;i<as.length;i++)
System.out.println(as[i]);
This works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With