const regex = /^(?:(?:\s{4}|\t)*(?:[^a]t|a[^t]|at[^\s]+)|[^\s]+).*/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?:(?:\\s{4}|\\t)*(?:[^a]t|a[^t]|at[^\\s]+)|[^\\s]+).*', 'gm')
const str = `---------- snippet start ----------
JUnit version 4.11
I.E
Time: 0.015
There was 1 failure:
1) testPerson(PersonTest)
org.junit.ComparisonFailure: expected:<John[1]> but was:<John[]>
a t org.junit.Assert.assertEquals(Assert.java:115)
attention org.junit.Assert.assertEquals(Assert.java:144)
at PersonTest.testPerson(PersonTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.ParentRunner\$3.run(ParentRunner.java:238)
---------- snippet end----------`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions