@SuppressWarnings("regex") public static PatternSyntaxException regexException(String s,int groups){
  try {
    Pattern p=Pattern.compile(s);
    int actualGroups=getGroupCount(p);
    if (actualGroups < groups) {
      return new PatternSyntaxException(regexErrorMessage(s,groups,actualGroups),s,-1);
    }
  }
 catch (  PatternSyntaxException pse) {
    return pse;
  }
  return null;
}

@ SuppressWarnings ( "regex" ) public static PatternSyntaxException regexException ( String s , int groups ) { try { Pattern p = Pattern . compile ( s ) ; int actualGroups = getGroupCount ( p ) ; if ( actualGroups < groups ) { return new PatternSyntaxException ( regexErrorMessage ( s , groups , actualGroups ) , s , - 1 ) ; } } catch ( PatternSyntaxException pse ) { return pse ; } return null ; }
returns null if the argument is a syntactically valid regular expression with at least the given number of groups . otherwise returns a patternsyntaxexception describing why the argument is not a regex .
