regex-specificity-2025.12.1 has been yanked.
regex-specificity
A fast, heuristic-based library to calculate the specificity of a regular expression pattern against a specific string.
Concept
Specificity measures how "precise" a match is. For example, the pattern abc is more specific to the string "abc" than the pattern a.c or .*.
The calculation follows these principles:
- Positional Weighting: Earlier matches contribute more to the total score than later ones.
- Certainty: Literals (exact characters) score higher than character classes or wildcards.
- Information Density: Narrower character classes (e.g.,
[a-z]) score higher than broader ones (e.g.,.). - Branching Penalty: Patterns with many alternatives (alternations) are penalized as they are less specific.
Usage
⚠️ Warning
The get function assumes that the string provided is already a full match for the pattern.
If the pattern does not match the string, the resulting score will be mathematically inconsistent and meaningless for comparison purposes.
use get;
License
This project is licensed under the MIT License © 2025 557.