I want to extract the exception name from the below sentences using regex pattern,
I need the terms RuntimeException and NullPointerException with a single Regex pattern.
This expression might help you to do so:
([A-Za-z]+Exception)
This graph shows how the expression would work and you can visualize your expressions in this link:
This JavaScript snippet shows the performance of that expression using a simple 1-million times for
loop.
repeat = 1000000;
start = Date.now();
for (var i = repeat; i >= 0; i--) {
var string = 'Error: android.java.lang.NullPointerException.checked';
var regex = /(.*)\.([A-Za-z]+Exception)(.*)/g;
var match = string.replace(regex, "$2");
}
end = Date.now() - start;
console.log("YAAAY! \"" + match + "\" is a match 💚💚💚 ");
console.log(end / 1000 + " is the runtime of " + repeat + " times benchmark test. 😳 ");