import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<!(?:\\/\\/|\\*).*)((?:export|import)[\\s\\w*,\\{\\}]*(?=\\sfrom)|export\\b\\s*(?:[*\\{]|\\w\\s?.+)|await import|import\\.meta\\.(?:env(?:\\.\\w+)?|resolve|url))";
final String string = "import * as foo from 'foo'\n"
+ "import { foo } from 'foo'\n"
+ "import {\n"
+ " foo,\n"
+ " bar\n"
+ "} from 'foo'\n"
+ "import.meta.env\n"
+ "import.meta.env.foo\n"
+ "import.meta.url\n"
+ "import.meta.resolve\n"
+ "export * from './foo' \n"
+ "export { default } from './foo'\n"
+ "export {\n"
+ " foo,\n"
+ " bar\n"
+ "} from 'foo'\n"
+ "export async function\n\n"
+ "// export async function\n\n"
+ "/**\n"
+ " *\n"
+ " * @example\n"
+ " * export default foo = 123\n"
+ " *\n"
+ " */\n"
+ " \n"
+ "await import\n"
+ " \n"
+ "export default foo\n"
+ "export default function foo\n"
+ "export default () => {\n"
+ "}\n"
+ "export class\n"
+ "export type";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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