regex or indexOf to extract text between ( )

Benchmark created on


Setup

const x = "myexpression( some stuff here ( including more ()))"

Test runner

Ready to run.

Testing in
TestOps/sec
regex capture
    let contents = (x.match(/\((.*)\)$/) || [null, ""])[1].trim();
    
    return true;
ready
index and lastindex of
let contents = x.substring(x.indexOf("("), x.lastIndexOf(")")).trim();


return true;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.