0

What expression to detect number between 200 and 299 has better performance:

1. /^2[0-9][0-9]/
2. /^2\d{2}/
  • It might even be faster to convert to int and compare. Depends on how well the regex engine does set lookups. – Zan Lynx Oct 23 '20 at 07:59

1 Answers1

1

Generic answer is: 2nd one will be better as it will match in 4 steps while the 1st one will require 5 steps, you can use i.e. https://regex101.com/ website which has regex debugger to play with them.

However in production it might heavily depend on underlying programming language regular expressions parsing engine and you will need to consider more factors like resources consumption so it's better to compare 2 implementations using a microbenchmark library for your programming language or even a load testing tool to mimic real-life conditions of usage of your function

Dmitri T
  • 159,985
  • 5
  • 83
  • 133