public static Rule parse(String rule) {
      Matcher m = PATTERN_RULE_PARSE.matcher(rule);
      if (!m.matches()) {
        throw new IllegalArgumentException("Invalid rule: " + rule);
      }
      int expectedComponentCount = Integer.parseInt(m.group(1));
      String matchPattern = m.group(2);
      String optionalPatternRealm = m.group(3);
      String matchingRegexp = m.group(4);
      String replacementPattern = m.group(5);
      String replacementReplacement = m.group(6);
      String replacementModifier = m.group(7);
      String caseSensitivity = m.group(8);
      return new Rule(
        new MatchingRule(expectedComponentCount, matchPattern, optionalPatternRealm),
        new Principal(matchingRegexp),
        new Substitution(replacementPattern, replacementReplacement, replacementModifier, !caseSensitivity.isEmpty()));
    }
@param rule in the following format RULE:[n:string](regexp)s/pattern/replacement/[modifier]/[L]
ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java