在RegEx中重复模式

Sac*_*hin 0 java regex

我有一个与下面的模式匹配的字符串部分.

abcd |(| a | ab | abc)e(fghi |(| f | fg | fgh)jklmn)

但我遇到的问题是,我的整个字符串是重复上述类似模式的组合.而我的整个字符串必须包含超过14套以上的模式.
任何人都可以帮我改进上面的RegEx到想要的格式.

谢谢

更新
输入示例:
匹配的字符串部分:abcd,abefgjkln,efjkln,ejkln
但整个字符串是:abcdabefgjklnefjklnejkln(以上4个部分的组合)

整个字符串中必须有超过15个部分.上面只有4个部分.所以,这是错的.

Fai*_*Dev 5

这将尝试在字符串中匹配您的"部分"至少15次.

    boolean foundMatch = false;
    try {
        foundMatch = subjectString.matches("(?:(?:ab(?:cd|efgjkln))|(?:(?:ef?jkln))){15,}");
    } catch (PatternSyntaxException ex) {
        // Syntax error in the regular expression
    }
Run Code Online (Sandbox Code Playgroud)

如果上述任何部分中至少有15次重复,则发现匹配将为真,否则它将保持为假.

分解 :

"(?:" +                       // Match the regular expression below
   "|" +                         // Match either the regular expression below (attempting the next alternative only if this one fails)
      "(?:" +                       // Match the regular expression below
         "ab" +                        // Match the characters “ab” literally
         "(?:" +                       // Match the regular expression below
                                          // Match either the regular expression below (attempting the next alternative only if this one fails)
               "cd" +                        // Match the characters “cd” literally
            "|" +                         // Or match regular expression number 2 below (the entire group fails if this one fails to match)
               "efgjkln" +                   // Match the characters “efgjkln” literally
         ")" +
      ")" +
   "|" +                         // Or match regular expression number 2 below (the entire group fails if this one fails to match)
      "(?:" +                       // Match the regular expression below
         "(?:" +                       // Match the regular expression below
            "e" +                         // Match the character “e” literally
            "f" +                         // Match the character “f” literally
               "?" +                         // Between zero and one times, as many times as possible, giving back as needed (greedy)
            "jkln" +                      // Match the characters “jkln” literally
         ")" +
      ")" +
"){15,}"                      // Between 15 and unlimited times, as many times as possible, giving back as needed (greedy)
Run Code Online (Sandbox Code Playgroud)