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 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/.createPartialMatchRegexRegex();
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 with variable-length captures cannot be partially matched** due to ambiguity in how the pattern should be matched. While simple fixed-length backreferences like `/(abc)\1/` could theoretically be transformed (if accepting that the group indexes would be polluted, compared to the original), to become `/(?:(a)|$)(?:(b)|$)(?:(c)|$)(?:\1|$)(?:\2|$)(?:\3|$)/` variable-length patterns break down.
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
- For example, with `/(\w+) \1/` (matches "hello hello"):
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
@@ -1,4 +1,4 @@
1
- import toPartialMatch from "./index.js";
1
+ import createPartialMatchRegex from "./index.js";
2
2
  RegExp.prototype.toPartialMatchRegex = function () {
3
- return toPartialMatch(this);
3
+ return createPartialMatchRegex(this);
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "regex-partial-match",
3
- "version": "0.1.4",
3
+ "version": "0.1.7",
4
4
  "description": "A regular expression transform for partial matching",
5
5
  "engines": {
6
6
  "node": ">=23"