import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<!(?:\\\\{2})*\\\\)(?:(?<begin_capture>[\\(])(?<begin_capture_modifier>(?=[<][a-z_A-Z]+[>])|(?!\\?(?:<?[=!]|:)))|(?<begin_non_capture>\\((?=\\?(?:<?[=!]|:))))|(?:(?<end>\\)))";
final String string = "// Basic - Repeat Delimiters\n"
+ "/^((?:([gimsuy])(?!.*\\\\2))*)/gm\n\n"
+ "// Basic - Nested - Captured | Non-captured\n"
+ "^(?:(// +)(?:(@noframes)([ \\t]*$)|(@(?:include|match|grant|require))([\\t ]+)(?:(https?.+?)|(.+))(\\**)([ \\t]*)|(^//[ \\t]+)(@(?:author|name(?:space)?|version|description))([ \\t]+)(.+?)([ \\t]*)|(^//[ \\t]+)(@resource)([ \\t]+)(\\S+)([ \\t]+)(\\S+)([ \\t]*))(\\n(?://[ \\t]*\\n)*))\n\n"
+ "// Basic - Captured | Non-captured | Lookbehind Positive\n"
+ "(?<=^[ \\t]*)(//)([ ])(?<capture_name>)(Case:)([ \\t]+)(.*\\S)([ \\t]*)?$\n\n"
+ "// Complex\n"
+ "(?<=^[ \\t]*)(//)([ ])(Case:)([ \\t]+)(.*\\S)([ \\t]*)?$\n\n"
+ "^(?:(?:(?:[0]*|[0]*1)(?=$))|(?:(?:[0]*|[0]*1(?[1-9]+)))?[\\.][\\d]+)$\n\n"
+ "^((?:[ ]{2})*[ ])([#])([ ]+)(?:(@param)([ ]+)(?:([\\$][\\d\\*@$?&]+))(\\??)(?:(:)([\\t ]+)(\\w+))?(?:([ ]+)([=][>])([ ]+)(?:([A-Za-z_-](?:[<][^\\n>]+[>]|[A-Za-z_-]*[^\\n]*?))(?:([ ]+)(?:(@desc)|([<]\\?))([ ]+)(.+?))?))([ ]*)|(@return)(?:([ ]+)([=][>])([ ]+)(?:([A-Za-z_][A-Za-z_]*)(.*?)(?:([ ]+)(?:(@desc)|([<]\\?))([ ]+)(.+?))?)))$";
final String subst = "\\n - $begin_capture";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html