Match Legals

Benchmark created on


Setup



const legalRegex = /\${LEGAL\.([^}]+)}/gi
const nonIndexedLegalRegex = /\${NONINDEX_LEGAL.([^}]+)?}/gi

const input = 'Example ${LEGAL.group1} ${LEGAL.group2} ${LEGAL.group3}';

Test runner

Ready to run.

Testing in
TestOps/sec
Match with For

const legalEntries = [];

  for (const match of input.matchAll(legalRegex)) {
    legalEntries.push(match[1]);
  }
  
  
const nonIndexedLegalEntries = [];

  for (const match of input.matchAll(nonIndexedLegalRegex)) {
    nonIndexedLegalEntries.push(match[1]);
  }
  
  
  
ready
Exec with while


const legalEntries = [];
while ((match = legalRegex.exec(input)) !== null) {
  legalEntries.push(match[1]);
}


const nonIndexedLegalEntries = [];
while ((match = nonIndexedLegalRegex.exec(input)) !== null) {
  nonIndexedLegalEntries.push(match[1]);
}


  
  
ready
Match with Spread
const legalEntries = [...input.matchAll(legalRegex)].map(match => match[1]);
const nonIndexedLegalEntries = [...input.matchAll(nonIndexedLegalRegex)].map(match => match[1]);
ready
Original match and map

  const legalEntries = input.match(legalRegex) || []
  const nonIndexedLegalEntries = input.match(nonIndexedLegalRegex) || []
  
  const legalKeys = legalEntries.map((legalEntry) => legalEntry.split('${LEGAL.')[1].split('}')[0])
  const nonIndexedLegalKeys = nonIndexedLegalEntries.map(
    (nonIndexedLegalEntry) => nonIndexedLegalEntry.split('${NONINDEX_LEGAL.')[1].split('}')[0]
  )
ready

Revisions

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