Java Regex
This regex pattern can be used to find Java source code comments that start with /* and end with */
(?s)/\*(.)*?\*/
Java source file we want to search for the comments:
/** * Test java source. */ public class TestSource { /** * doSomething * * @param arg */ public void doSomething (Object arg) { } /** * @param args */ public static void main (String[] args) { } }
Using Regex:
public static void main (String[] args) throws Exception { String source = getJavaSource(); Pattern pattern = Pattern.compile("(?s)/\\*(.)*?\\*/"); Matcher matcher = pattern.matcher(source); while (matcher.find()) { System.out.println(matcher.group()); } }
Output:
/** * Test java source. */ /** * doSomething * * @param arg */ /** * @param args */
Dependencies and Technologies Used: