You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/2.getting-started/2.usage.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,9 +56,15 @@ All of the helpers above return an object of type `Input` that can be chained wi
56
56
|`after`, `before`, `notAfter` and `notBefore`| these activate positive/negative lookahead/lookbehinds. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari). |
57
57
|`times`| this is a function you can call directly to repeat the previous pattern an exact number of times, or you can use `times.between(min, max)` to specify a range, `times.atLeast(num)` to indicate it must repeat x times or `times.any()` to indicate it can repeat any number of times, _including none_. |
58
58
|`optionally`| this is a function you can call to mark the current input as optional. |
59
-
|`as`| this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()`. |
59
+
|`as`| alias for `groupedAs`|
60
+
|`groupedAs`| this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()`. |
61
+
|`grouped`| this defines the entire input so far as an anonymous group. |
60
62
|`at`| this allows you to match beginning/ends of lines with `at.lineStart()` and `at.lineEnd()`. |
61
63
64
+
::alert
65
+
By default, for better regex performance, creation input helpers such as `anyOf`, `maybe`, `oneOrMore`, and chaining input helpers such as `or`, `times(.between/atLeast/any)`, or `optionally` will wrap the input in a non-capturing group with `(?:)`. You can use chaining input helper `grouped` after any `Input` type to capture it as an anonymous group.
66
+
::
67
+
62
68
## Debugging
63
69
64
70
When using `magic-regexp`, a TypeScript generic is generated for you that should show the RegExp that you are constructing, as you go.
/** this is a positive lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) */
/** this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()`. Alias for `groupedAs` */
54
+
as: <Kextendsstring>(
55
+
key: K
56
+
)=>Input<`(?<${K}>${Vextends `(?:${infer Sextendsstring})` ? S : V})`,G|K>
46
57
/** this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()` */
0 commit comments