6 Replies Latest reply: Oct 14, 2006 3:32 PM by 807607 RSS

    Matching bracket in a regular expression

    807607
      I have a String consists of nested round brackets with some content in it and follows a pattern. I want to use Regular Expression to group such occurances. For ex, The String is:
      String str = "(Living being: (cow: type (Animal) walks, motion (legs(4))) "+
               "(Hen: type (bird) flies) "+
               "(Caterpillar: type(worm) food(plants(green leaves)) color(green, red, yellow))"+
                " (Dog: type(Animal)) )";
      I want to formulate a regular expression, such that, if I pass a word,
      (cow:
      , the matcher group should return
      (cow: type (Animal) walks. motion (legs(4)))
      and for a word
      (Dog:
      , the result should be
      (Dog: type(Animal) )
      So, for a matching word it should return complete content-set for the matching bracket. Any clues are welcome. Thanks.