Groovy or java: how to get a block of comments using regex from / ** *** /?


This might be a piece of cake for java experts. Please help me out:

I have a block of comments in my program like this:

block of comments - line 1
line 2

How could I retrieve "block of comments" using regex?


Something like this should do:

    String str =
        "some text\n"+
        "/*********\n" +
        "block of comments - line 1\n" +
        "line 2\n"+
        "....\n" +
        "***/\n" +
        "some more text";

    Pattern p = Pattern.compile("/\\*+(.*?)\\*+/", Pattern.DOTALL);
    Matcher m = p.matcher(str);

    if (m.find())

(DOTALL says that the . in the pattern should also match new-line characters) Prints:

block of comments - line 1
line 2