JavaScript / ECMAScript

Java Stack Trace Line in JS

Matches a single Java stack trace frame line.

Try it in the JS tester →

Pattern

regexJS
^\s*at\s+([\w$.]+)\(([^)]+)\)$   (flags: gm)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^\\s*at\\s+([\\w$.]+)\\(([^)]+)\\)$", "gm");
const input = "\tat com.example.MyClass.method(MyClass.java:42)";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

`^\s*at\s+` matches the indent and 'at' keyword. `([\w$.]+)` captures the fully-qualified method. `\(([^)]+)\)$` captures the source location.

Examples

Input

at com.example.MyClass.method(MyClass.java:42)

Matches

  • at com.example.MyClass.method(MyClass.java:42)

Same pattern, other engines

← Back to Java Stack Trace Line overview (all engines)