import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:[ab]/)?([^ \\t\\n\\r\\f\\v:\"]+\\.(?:html|py|css|js|txt|xml|json|vue))(?:\". line |[:\\n ])";
final String string = "diff --git a/src/give/forms.py b/src/give/forms.py\n\n\n"
+ " M give/locale/fr/LC_MESSAGES/django.po\n"
+ " M agive/models/translation.py\n"
+ " M give/views.py\n\n"
+ "Some problem at give/widgets.py:103\n\n"
+ "Traceback (most recent call last):\n"
+ " File \"/usr/lib/python3.10/unittest/case.py\", line 59, in testPartExecutor\n"
+ " yield\n"
+ " File \"/usr/lib/python3.10/unittest/case.py\", line 587, in run\n"
+ " self._callSetUp()\n"
+ " File \"/usr/lib/python3.10/unittest/case.py\", line 546, in _callSetUp\n"
+ " self.setUp()\n"
+ " File \"/home/projects/src/give/tests/test_models.py\", line 14, in setUp\n";
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