Returns the number of strings that match the given RegExp or undefined if there are infinitely many matches.
import { size } from'@gruhn/regex-utils'
size(/^[a-z]$/) === 26n
size(/^[a-z][0-9]$/) === 260n
// this one has infinitely many matches: size(/^[a-z]*$/) === undefined
// that's why the return type is `bigint`; size(/^[a-z]{60}/) === 7914088058189701615326255069116716194962212229317838559326167922356251403772678373376n
Note
Double counting is often avoided.
For example, size(/^(hello|hello)$/) is only 1n and not 2n.
But it probably still happens.
The value should always be an upper bound though.
Returns the number of strings that match the given
RegExp
orundefined
if there are infinitely many matches.Double counting is often avoided. For example,
size(/^(hello|hello)$/)
is only1n
and not2n
. But it probably still happens. The value should always be an upper bound though.