regex-partial-match 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/lib/index.js +13 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,25 +69,27 @@ Such combinations have not been tested.
|
|
|
69
69
|
## Supported Features
|
|
70
70
|
|
|
71
71
|
- 🔤 [Literal characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Literal_character)
|
|
72
|
-
- 📋 [Character classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class) (`[abc]`, `[^abc]`, `[a-z]`)
|
|
73
72
|
- 🔣 [Character escapes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape) (`\n`, `\t`, `\x61`, `\u0061`, `\u{1F600}`)
|
|
73
|
+
- 🧩 [Character class escapes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class_escape): `/\w+/`, `/\d{3}/`
|
|
74
74
|
- 🌐 [Unicode character class escape](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape) (`\p{Letter}`, `\P{Letter}`)
|
|
75
|
+
- 📋 [Character classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class) (`[abc]`, `[^abc]`, `[a-z]`)
|
|
75
76
|
- 🧮 [Unicode sets (`v` flag)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) (`/[\p{Lowercase}&&\p{Script=Greek}]/v`)
|
|
76
77
|
- 🔢 [Quantifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Quantifier) (`*`, `+`, `?`, `{n}`, `{n,}`, `{n,m}`)
|
|
77
78
|
- 🔀 [Disjunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Disjunction) (`a|b`)
|
|
78
79
|
- 👥 [Groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Capturing_group) (capturing and non-capturing) (`(?:abc)`, `(abc)`, `(?<named>abc)`)
|
|
79
|
-
-
|
|
80
|
+
- 👉 [Lookahead assertions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_assertion) (`(?=...)`, `(?!...)`)
|
|
80
81
|
- 👈 [Lookbehind assertions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookbehind_assertion) (`(?<=...)`, `(?<!...)`)
|
|
81
82
|
- ⚓ [Input Boundaries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Input_boundary_assertion) (`^`, `$`)
|
|
82
83
|
- 🆒 [Word Boundaries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Word_boundary_assertion) (`\b`, `\B`)
|
|
83
84
|
- 🏴 [Flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags): `g`, `i`, `m`, `s`, `u`, `d`, `y` (See [caveats](#sticky-flag-y) for `y`)
|
|
85
|
+
- 🎚️ [Modifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier) (`(?ims:...)`, `(?-ims:...)`, `(?im-s:...)`)
|
|
84
86
|
|
|
85
87
|
## Unsupported Features
|
|
86
88
|
|
|
87
89
|
The following regex features are **not currently supported**:
|
|
88
90
|
|
|
89
91
|
- ⚠️ [Backreferences](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Backreference) (`\1`, `\k<name>`) - Can be included, but can't partially match. See [caveats](#caveats).
|
|
90
|
-
-
|
|
92
|
+
- ⚠️ [Character class substrings](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class#matching_strings) (`\q{abc}`) - When used independently, rather than to modify, can be included, but can't partially match. See [caveats](#caveats).
|
|
91
93
|
|
|
92
94
|
## Browser Compatibility
|
|
93
95
|
|
|
@@ -99,6 +101,8 @@ The library is compiled to **ES5** for broad compatibility with older browsers a
|
|
|
99
101
|
- [**Named capturing groups**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_capturing_group) (`(?<name>...)`) - ES2018+
|
|
100
102
|
- [**`s` (dotAll) flag**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll) - ES2018+
|
|
101
103
|
- [**`d` (hasIndices) flag**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices) - ES2022+
|
|
104
|
+
- [**`v` (unicodeSets) flag**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) - ES2024+
|
|
105
|
+
- [**Modifiers**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier) (`(?ims:...)`, `(?-ims:...)`, `(?i-ms:...)`) - ES2025+
|
|
102
106
|
|
|
103
107
|
## Caveats
|
|
104
108
|
|
|
@@ -178,6 +182,14 @@ The **global flag is preserved** but may not be necessary for partial matching u
|
|
|
178
182
|
|
|
179
183
|
The global flag does not cause issues like the sticky flag, as partial patterns naturally match from the beginning of the input. However, if you're using `lastIndex` to track position, be aware that failed matches will reset it to 0.
|
|
180
184
|
|
|
185
|
+
### "String properties"
|
|
186
|
+
|
|
187
|
+
As with surrogate pair matching, grapheme clusters / string properties can only match atomically.
|
|
188
|
+
|
|
189
|
+
Hence, `[\p{RGI_Emoji_Flag_Sequence}]` will match `🇺🇳` as a whole, but not as the individual code points of which it's comprised.
|
|
190
|
+
|
|
191
|
+
In [`v` mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) expressions, where `[\q{abc}]` syntax is used in isolation (rather than its canonical use-case as a subtraction/intersection of another character class), this will also only match entirely or not at all. i.e. `abc` can match, but not partially.
|
|
192
|
+
|
|
181
193
|
## Examples
|
|
182
194
|
|
|
183
195
|
### Form Validation
|
package/lib/index.js
CHANGED
|
@@ -102,21 +102,30 @@ var createPartialMatchRegex = function (regex) {
|
|
|
102
102
|
i += 3;
|
|
103
103
|
result += process() + ")";
|
|
104
104
|
break;
|
|
105
|
+
case "-":
|
|
106
|
+
case "i":
|
|
107
|
+
case "s":
|
|
108
|
+
case "m":
|
|
109
|
+
var temp = i + 2, temp2 = source.indexOf(":", temp);
|
|
110
|
+
result += "(?" + source.substring(temp, temp2) + ":";
|
|
111
|
+
i = temp2 + 1;
|
|
112
|
+
result += process() + ")";
|
|
113
|
+
break;
|
|
105
114
|
case "!": {
|
|
106
|
-
var
|
|
115
|
+
var temp_1 = i;
|
|
107
116
|
i += 3;
|
|
108
117
|
process();
|
|
109
|
-
result += source.substring(
|
|
118
|
+
result += source.substring(temp_1, i);
|
|
110
119
|
break;
|
|
111
120
|
}
|
|
112
121
|
case "<":
|
|
113
122
|
switch (source[i + 3]) {
|
|
114
123
|
case "=":
|
|
115
124
|
case "!": {
|
|
116
|
-
var
|
|
125
|
+
var temp_2 = i;
|
|
117
126
|
i += 4;
|
|
118
127
|
process();
|
|
119
|
-
result += source.substring(
|
|
128
|
+
result += source.substring(temp_2, i);
|
|
120
129
|
break;
|
|
121
130
|
}
|
|
122
131
|
default:
|