@ptolemy2002/rgx 7.0.0 → 7.1.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
CHANGED
|
@@ -1354,6 +1354,8 @@ A pre-built `RegExpFlagTransformer` that makes a regex pattern accent-insensitiv
|
|
|
1354
1354
|
- `o` / `O`: ó, ò, ö, ô, õ / Ó, Ò, Ö, Ô, Õ
|
|
1355
1355
|
- `u` / `U`: ú, ù, ü, û / Ú, Ù, Ü, Û
|
|
1356
1356
|
|
|
1357
|
+
Note that this transformer intentionally excludes replacing characters preceded by an odd number of backslashes, to allow for escaping. For example, in the pattern `\\a`, the `a` is preceded by two backslashes (an even number), so it will be replaced with `(a|á|à|ä|â|ã)`. In the pattern `\a`, the `a` is preceded by one backslash (an odd number), so it will not be replaced.
|
|
1358
|
+
|
|
1357
1359
|
#### Parameters
|
|
1358
1360
|
- `exp` (`RegExp`): The regular expression to transform.
|
|
1359
1361
|
|
|
@@ -1660,6 +1662,11 @@ Since these are defined as native tokens (strings), they are automatically wrapp
|
|
|
1660
1662
|
| `"non-word-char"` | `\W` | Any non-word character |
|
|
1661
1663
|
| `"backspace"` | `[\b]` | Backspace character |
|
|
1662
1664
|
|
|
1665
|
+
### Complex Constructs
|
|
1666
|
+
| Name | Resolves To | Description |
|
|
1667
|
+
| --- | --- | --- |
|
|
1668
|
+
| `"non-escape-bound"` | `(?<=(?<!\\)(?:\\\\)*)(?=[^\\]\|$)` | Matches a position that is not preceded by an odd number of backslashes, i.e., the next character is not escaped. Note that this doesn't match when the next character is a backslash, since allowing it to do that would cause non-escaped backslashes within a series of backslashes to be treated as escaped. For example, in the string `\\\a`, the first and third backslashes would be treated as escaped. |
|
|
1669
|
+
|
|
1663
1670
|
## Peer Dependencies
|
|
1664
1671
|
- `@ptolemy2002/immutability-utils` ^2.0.0
|
|
1665
1672
|
- `@ptolemy2002/js-utils` ^3.2.2
|
package/dist/constants.js
CHANGED
|
@@ -191,3 +191,12 @@ defineRGXConstant("backspace", {
|
|
|
191
191
|
return /[\b]/;
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
|
+
// Complex Constructs
|
|
195
|
+
// Put this before any pattern to ensure that the pattern is not escaped, i.e., not preceded by an odd number of backslashes.
|
|
196
|
+
defineRGXConstant("non-escape-bound", {
|
|
197
|
+
rgxGroupWrap: false,
|
|
198
|
+
rgxIsRepeatable: false,
|
|
199
|
+
toRgx() {
|
|
200
|
+
return /(?<=(?<!\\)(?:\\\\)*)(?=[^\\]|$)/;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.accentInsensitiveFlagTransformer = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const resolve_1 = require("../resolve");
|
|
4
6
|
const accentPatterns = [
|
|
5
7
|
"(a|á|à|ä|â|ã)", "(A|Á|À|Ä|Â|Ã)",
|
|
6
8
|
"(e|é|è|ë|ê)", "(E|É|È|Ë|Ê)",
|
|
@@ -11,9 +13,10 @@ const accentPatterns = [
|
|
|
11
13
|
const accentInsensitiveFlagTransformer = function (exp) {
|
|
12
14
|
let source = exp.source;
|
|
13
15
|
const flags = exp.flags;
|
|
16
|
+
const nonEscapeBound = (0, resolve_1.resolveRGXToken)((0, constants_1.rgxConstant)("non-escape-bound"));
|
|
14
17
|
accentPatterns.forEach((pattern) => {
|
|
15
18
|
// Replace any of the characters in the pattern with the pattern itself
|
|
16
|
-
source = source.replaceAll(new RegExp(pattern, "g"), pattern);
|
|
19
|
+
source = source.replaceAll(new RegExp(nonEscapeBound + pattern, "g"), pattern);
|
|
17
20
|
});
|
|
18
21
|
return new RegExp(source, flags);
|
|
19
22
|
};
|