I am working on a personal project where I need to extract the actual comments from an input string like this.
Case 1: /* Some useful text */
Output: Some useful text
Case 2: /*** This is formatted obnoxiously**/
Output: This is formatted obnoxiously
Case 3:
/**
More useful
information
*/
Output: More useful information
Case 4:
/**
Prompt the user to type in
the number. Assign the number to v
*/
Output: Prompt the user to type in the number. Assign the number to v
I am working in Java and I have tried to replace /*
and */
using naive method such as String.replace
but since a comment can be formatted in different ways like above, the replace
method seems not to be a viable approach to do this. How can I achieve the above outputs using regex?
Here is the test comment file that I am using.