Takes a sequence of regular expressions and constructs their intersection.
This is useful to combine several constraints into one.
For example, to build a regular expression that can validate a new password:
import { intersection } from'@gruhn/regex-utils'
constpasswordRegex = intersection( /.{12,}/, // 12 letters or more /[0-9]/, // at least one number /[A-Z]/, // at least one upper case letter /[a-z]/, // at least one lower case letter )
Takes a sequence of regular expressions and constructs their intersection. This is useful to combine several constraints into one. For example, to build a regular expression that can validate a new password:
In most cases it's simpler and more efficient to match each
RegExp
individually:However, this is not always possible. For example, when a third-party interface expect a single
RegExp
as input like: