regex-partial-match 0.2.1 → 0.4.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/LICENSE +1 -1
- package/README.md +3 -2
- package/lib/index.js +27 -4
- package/package.json +3 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
ISC License
|
|
2
2
|
|
|
3
|
-
Copyright 2025 Tom Pereira (https://github.com/TomStrepsil)
|
|
3
|
+
Copyright 2025-2026 Tom Pereira (https://github.com/TomStrepsil)
|
|
4
4
|
|
|
5
5
|
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ This allows the pattern to match prefixes of the original pattern, enabling vali
|
|
|
56
56
|
|
|
57
57
|
Since the library accepts only valid regular expressions [^1], this enables the algorithm to make lots of unguarded assumptions about the source of the expression.
|
|
58
58
|
|
|
59
|
-
The library has been stress-tested with various regular expression features in isolation, and some in likely combination, but obviously
|
|
59
|
+
The library has been stress-tested with various regular expression features in isolation, and some in likely combination, but obviously it's an unbounded test space, and syntactically valid regular expressions nevertheless support contradictory patterns e.g.
|
|
60
60
|
|
|
61
61
|
- `/\b\B/` - impossible to match both a word boundary and a non-word boundary
|
|
62
62
|
- `/$^/` - end cannot come before start
|
|
@@ -82,6 +82,7 @@ Such combinations have not been tested.
|
|
|
82
82
|
- ⚓ [Input Boundaries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Input_boundary_assertion) (`^`, `$`)
|
|
83
83
|
- 🆒 [Word Boundaries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Word_boundary_assertion) (`\b`, `\B`)
|
|
84
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:...)`)
|
|
85
86
|
|
|
86
87
|
## Unsupported Features
|
|
87
88
|
|
|
@@ -89,7 +90,6 @@ The following regex features are **not currently supported**:
|
|
|
89
90
|
|
|
90
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).
|
|
91
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).
|
|
92
|
-
- ❌ [Modifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier) (`(?ims:...)`, `(?-ims:...)`) - ES2025+. See [issue](https://github.com/TomStrepsil/regex-partial-match/issues/2).
|
|
93
93
|
|
|
94
94
|
## Browser Compatibility
|
|
95
95
|
|
|
@@ -102,6 +102,7 @@ The library is compiled to **ES5** for broad compatibility with older browsers a
|
|
|
102
102
|
- [**`s` (dotAll) flag**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll) - ES2018+
|
|
103
103
|
- [**`d` (hasIndices) flag**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices) - ES2022+
|
|
104
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+
|
|
105
106
|
|
|
106
107
|
## Caveats
|
|
107
108
|
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
var occurrencesRegex = /\{\d+,?\d*\}/g;
|
|
2
|
+
var notNumbersRegex = /\D/g;
|
|
2
3
|
var createPartialMatchRegex = function (regex) {
|
|
3
4
|
var source = regex.source;
|
|
4
5
|
var isUnicode = regex.unicode || regex.unicodeSets;
|
|
@@ -44,6 +45,19 @@ var createPartialMatchRegex = function (regex) {
|
|
|
44
45
|
case "x":
|
|
45
46
|
appendOptional(4);
|
|
46
47
|
break;
|
|
48
|
+
case "1":
|
|
49
|
+
case "2":
|
|
50
|
+
case "3":
|
|
51
|
+
case "4":
|
|
52
|
+
case "5":
|
|
53
|
+
case "6":
|
|
54
|
+
case "7":
|
|
55
|
+
case "8":
|
|
56
|
+
case "9":
|
|
57
|
+
notNumbersRegex.lastIndex = i + 1;
|
|
58
|
+
var nextNonDigit = notNumbersRegex.exec(source);
|
|
59
|
+
appendOptional((nextNonDigit ? nextNonDigit.index : source.length) - i);
|
|
60
|
+
break;
|
|
47
61
|
default:
|
|
48
62
|
appendOptional(2);
|
|
49
63
|
break;
|
|
@@ -102,21 +116,30 @@ var createPartialMatchRegex = function (regex) {
|
|
|
102
116
|
i += 3;
|
|
103
117
|
result += process() + ")";
|
|
104
118
|
break;
|
|
119
|
+
case "-":
|
|
120
|
+
case "i":
|
|
121
|
+
case "s":
|
|
122
|
+
case "m":
|
|
123
|
+
var temp = i + 2, temp2 = source.indexOf(":", temp);
|
|
124
|
+
result += "(?" + source.substring(temp, temp2) + ":";
|
|
125
|
+
i = temp2 + 1;
|
|
126
|
+
result += process() + ")";
|
|
127
|
+
break;
|
|
105
128
|
case "!": {
|
|
106
|
-
var
|
|
129
|
+
var temp_1 = i;
|
|
107
130
|
i += 3;
|
|
108
131
|
process();
|
|
109
|
-
result += source.substring(
|
|
132
|
+
result += source.substring(temp_1, i);
|
|
110
133
|
break;
|
|
111
134
|
}
|
|
112
135
|
case "<":
|
|
113
136
|
switch (source[i + 3]) {
|
|
114
137
|
case "=":
|
|
115
138
|
case "!": {
|
|
116
|
-
var
|
|
139
|
+
var temp_2 = i;
|
|
117
140
|
i += 4;
|
|
118
141
|
process();
|
|
119
|
-
result += source.substring(
|
|
142
|
+
result += source.substring(temp_2, i);
|
|
120
143
|
break;
|
|
121
144
|
}
|
|
122
145
|
default:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "regex-partial-match",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A regular expression transform for partial matching",
|
|
5
5
|
"devEngines": {
|
|
6
6
|
"runtime": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"version": ">=23"
|
|
9
9
|
},
|
|
10
10
|
"packageManager": {
|
|
11
|
-
"name": "npm"
|
|
11
|
+
"name": "npm",
|
|
12
|
+
"version": "^11"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|