Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8132141

The matching of a string against a regular expression takes long time

XMLWordPrintable

      The provided test runs for more than an hour.
      With some little modifications to the regex pattern (equivalent) the app runs fast.

      import java.util.*;
      import java.util.regex.*;
      public class ErrRegex {
          public static void main(String[] args){
              System.out.printf("%s java\n",new Date().toString());
              Pattern p =
      Pattern.compile("(h|h|ih(((i|a|c|c|a|i|i|j|b|a|i|b|a|a|j))+h)ahbfhba|c|i)*");
              Matcher m =
      p.matcher("hchcchicihcchciiicichhcichcihcchiihichiciiiihhcchicchhcihchcihiihci
      ichhccciccichcichiihcchcihhicchcciicchcccihiiihhihihihichicihhcciccchihhhcchic
      hchciihiicihciihcccciciccicciiiiiiiiicihhhiiiihchccchchhhhiiihchihcccchhhiiiii
      iiicicichicihcciciihichhhhchihciiihhiccccccciciihhichiccchhicchicihihccichicci
      ihcichccihhiciccccccccichhhhihihhcchchihihiihhihihihicichihiiiihhhhihhhchhichi
      icihhiiiiihchccccchichci");
              m.matches();
              System.out.printf("%s done java\n",new Date().toString());
          }
      }

        1. test.html
          0.7 kB
          Ting-Yun Ingrid Yao
        2. test.html
          0.7 kB
          Ting-Yun Ingrid Yao

            igerasim Ivan Gerasimov
            shadowbug Shadow Bug
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: