Short word + word boundaries or none

Benchmark created on


Description

Previously, it turned out that, for longer words, \b is better: https://jsperf.app/najotu

Test runner

Ready to run.

Testing in
TestOps/sec
With word boundaries
// Test Case 1: With word boundaries (\b)
const testWithBoundary = () => {
  const regex = /\b[Dd]is\b/;
  return regex.test("Dis") && !regex.test("DisX");
};
ready
Without word boundaries
// Test Case 2: Without word boundaries
const testWithoutBoundary = () => {
  const regex = /[Dd]is/;
  return regex.test("Dis") && regex.test("XDisY");
};
ready

Revisions

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