regex-partial-match 0.1.4 → 0.1.7
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 +3 -11
- package/lib/extend.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ partial.test("goodbye"); // false - cannot match
|
|
|
39
39
|
```javascript
|
|
40
40
|
import "regex-partial-match/extend";
|
|
41
41
|
|
|
42
|
-
const partial = /hello world/.
|
|
42
|
+
const partial = /hello world/.toPartialMatchRegex();
|
|
43
43
|
|
|
44
44
|
partial.test("hel"); // true
|
|
45
45
|
```
|
|
@@ -103,17 +103,9 @@ The library is compiled to **ES5** for broad compatibility with older browsers a
|
|
|
103
103
|
|
|
104
104
|
### Backreferences
|
|
105
105
|
|
|
106
|
-
**Backreferences
|
|
106
|
+
**Backreferences cannot be partially matched because they are atomic.** A backreference like `\1` must match the complete captured text or fail entirely, and cannot be split into individual characters for partial matching like regular atoms can.
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
- A naive transformation `/(?:(\w+)|$)(?:( )|$)(?:\1|$)/` creates ambiguity
|
|
111
|
-
- For input "hello h", the regex can match in multiple ways:
|
|
112
|
-
- Capture group 1 as "hello", skip the space with `$`, skip `\1` with `$` ✓
|
|
113
|
-
- Capture group 1 as "h", skip the space with `$`, match `\1` as "h" ✓ (at position 6)
|
|
114
|
-
- The engine chooses the second interpretation, matching just "h" instead of recognizing "hello h" as a partial match
|
|
115
|
-
|
|
116
|
-
The core issue: **the regex engine cannot determine which part of the input should be captured vs. which part should match the backreference** when dealing with variable-length patterns and incomplete input. Fixed-length patterns like `/(abc)\1/` avoid this ambiguity since each character position has a clear role.
|
|
108
|
+
Fixed-length patterns like `/(abc)\1/` could theoretically become `/(?:(a)|$)(?:(b)|$)(?:(c)|$)(?:\1|$)(?:\2|$)(?:\3|$)/` (accepting polluted capture indexes as a side-effect), but this doesn't work for variable-length captures.
|
|
117
109
|
|
|
118
110
|
### Surrogate Pair Matching
|
|
119
111
|
|
package/lib/extend.js
CHANGED