1 Reply Latest reply: Apr 30, 2008 11:41 PM by 800351 RSS

    Question on regex Matcher (group number)

    807591
      HI, everybody
      I am writing a program on replacement like the one below.
      String regex = "(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)";
      String original = "ABCDEFGHIJKL";
      String replacement = "$12";
      Pattern p = Pattern.compile(regex);
      Matcher m = p.matcher(original);
      String result = m.replaceFirst(replacement);
      What I actually want is to take out the first group, in this case an "A", and append a character "2" after it.
      The result I am expecting is "A2". But the result I get is "L". For the regex engine takes it as the 12th group.
      What should I do to remove the ambiguity.

      Thanks.