Getting bad results in my regular expression syntax

import java.util.regex.Matcher;

import java.util.regex.Pattern;

class RegualrExpression {

public static void main(String[] args) {
	
	String s = "000011";
	Pattern p = Pattern.compile("0|1[3,]");
	Matcher m = p.matcher(s);
	int c=0;
	while(m.find()){
		c++;
	}
	System.out.print(c);
}

}

Substrings are : 000 from index [0-2] ,000 from [1-3] , 0000 from [0-3]. so total 3 substrings.

I am using “0|1[3,]” expression to count those substrings of 0 or 1 which have length >=3 . result should be 3 but i am getting 0 here. please tell me the right way to do it.

your pattern string should be “[01]{3,}” or “(0|1){3,}”, but i think this string will return 1. It will consider whole string as one find.