public static boolean areRegexpModifiersValid(String flags){
  final int GROUP=1;
  final int CASE_INSENSITIVE=2;
  final int MULTILINE=4;
  int seen=0;
  for (int i=0, n=flags.length(); i < n; ++i) {
    char flag=flags.charAt(i);
    int flagMask;
switch (flag) {
case 'g':
      flagMask=GROUP;
    break;
case 'i':
  flagMask=CASE_INSENSITIVE;
break;
case 'm':
flagMask=MULTILINE;
break;
default :
return false;
}
if ((seen & flagMask) != 0) {
return false;
}
seen=seen | flagMask;
}
return true;
}

public static boolean areRegexpModifiersValid ( String flags ) { final int GROUP = 1 ; final int CASE_INSENSITIVE = 2 ; final int MULTILINE = 4 ; int seen = 0 ; for ( int i = 0 , n = flags . length ( ) ; i < n ; ++ i ) { char flag = flags . charAt ( i ) ; int flagMask ; switch ( flag ) { case 'g' : flagMask = GROUP ; break ; case 'i' : flagMask = CASE_INSENSITIVE ; break ; case 'm' : flagMask = MULTILINE ; break ; default : return false ; } if ( ( seen & flagMask ) != 0 ) { return false ; } seen = seen | flagMask ; } return true ; }
modifiers are the letters allowed to follow a regular expression literal . firefox does not recognize the " s " modifier , and no version of javascript deals with the " x " or " e " modifiers , so this regex matches g , i , and m in any order without duplicates .
