Expand description
§regex-specificity
This crate provides a heuristic-based approach 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 specificity than later ones.
- Certainty: Literals (exact characters) specificity higher than character classes or wildcards.
- Information Density: Narrower character classes (e.g.,
[a-z]) specificity higher than broader ones (e.g.,.). - Branching Penalty: Patterns with many alternatives (alternations) are penalized as they are less specific.
Functions§
- get
- Calculates the specificity of a pattern against a given string.