title: Pattern Error: Dangling meta character
body: <p>I want to build a pattern to insert comma into integer to make it looks nice , like <code>1234556</code>, after manipulating , it will be like <code>1,234,556</code> , so I use the following code:</p>
  
  <pre><code>public static void insertCommaFormly(int n)
      {
          String input = String.valueOf(n);
          String regex = "(?&lt;=\\d)(?=(?:\\d{3},?)+$)";
          /*or we can use negative look-around*/
          regex = "(?&lt;=\\d)(?=\\d{3}++\\b)";
          String replacement = ",";
          StringBuffer buffer = new StringBuffer();
          Pattern pattern = Pattern.compile(regex);
          Matcher matcher = pattern.matcher(input);
  
          logger.info("Target string is :" + input );
          logger.info("Use regex :" + regex);
  
          while(matcher.find())
          {
              matcher.appendReplacement(buffer, replacement);
              logger.info(String.format("Part : '%s'", buffer));
          }
          matcher.appendTail(buffer);
  
          logger.info("After replace , the string is like : " + buffer.toString());
      } 
  </code></pre>
  
  <p>However , it gives me an error(<code>I don't know the reason!</code>): </p>
  
  <pre><code>Dangling meta character '+' near index 16
  (?&lt;=\d)(?=\d{2}++\b)
                  ^
  </code></pre>
  
  <p>but if I use <code>(?&lt;=\\d)(?=\\d{3}+\\b)</code> , the compiler will not give me complaint , however , it gives me the wrong result <code>1234,556</code>(<code>I don't know why results in this ?</code>) ,if I use <code>(?&lt;=\\d)(?=(?:\\d{3})+\\b)</code>, then it would be the right result. </p>
  
  <pre><code>  So here are my two questions , please help me with these , thanks in advance!
  </code></pre>