Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kastoestoramadus/d02d1c9f9abec47e35640bef7fb1af2b to your computer and use it in GitHub Desktop.

Select an option

Save kastoestoramadus/d02d1c9f9abec47e35640bef7fb1af2b to your computer and use it in GitHub Desktop.
include regexp
import java.util.regex.*;
String hocon = """
include "a.conf"
include file("b.conf")
include required("c.conf")
include required file("bad.conf")
include required "also.bad.conf"
""";
Pattern p = Pattern.compile(
"(?m)^\\s*include\\s+(?:required\\(([^)]*)\\)|(?:file|url|classpath|resource)?\\(?\"?([^\"\\s)]+)\"?\\)?)"
);
Matcher m = p.matcher(hocon);
while (m.find()) {
String inner = m.group(1) != null ? m.group(1) : m.group(2);
System.out.println("FOUND: " + inner);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment