I have to match text between /*
and */
. These are java block comments.
For now I created program that doesn't work as intended because it doesn't stop at closing token */
. Here is code:
public static void main(String[] args) {
String s = "public void /* sdksd\n*k/sss\\d\nsd */ main class\n/*String s = null;*/trtgg";
Matcher matcher = Pattern.compile("(?s)/\\*(.*)(?=\\*/)").matcher(s);
while (matcher.find()) {
String group = matcher.group(1);
System.out.println("group="+group);
}
}
It prints:
group= sdksd
*k/sss\d
sd */ main class
/*String s = null;
Expected output is :
group= sdksd
*k/sss\d
sd
group=String s = null;
Why it doesn't stop at first closing token */
?
Is there other way to achieve this?