public static int getOccurrenceCount(String expr, String str)
    {
        int ret = 0;
        Pattern p = Pattern.compile(expr);
        Matcher m = p.matcher(str);
        while(m.find()) 
            ++ret;
        return ret;
    }
public static int getOccurrenceCount ( String expr , String str ) { int ret = 0 ; Pattern p = Pattern . compile ( expr ) ; Matcher m = p . matcher ( str ) ; while ( m . find ( ) ) ++ ret ; return ret ; }
Returns the number of occurrences of the substring in the given string.
@param expr The string to look for occurrences of
@param str The string to search
@return The number of occurences