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
+22-8
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ console.log(regExp)
15
15
16
16
Every pattern you create with the library should be wrapped in `createRegExp`, which enables the build-time transform.
17
17
18
-
The first argument is either a string to match exactly, or an input pattern built up using helpers from `magic-regexp`. It also takes a second argument, which is an array of flags or flags string.
18
+
`createRegExp` accepts an arbitrary number of arguments of type `string` or `Input` (built up using helpers from `magic-regexp`), and an optional final argument of an array of flags or a flags string. It creates a `MagicRegExp`, which concatenates all the patterns from the arguments that were passed in.
|`charIn`, `charNotIn`| this matches or doesn't match any character in the string provided. |
41
-
|`anyOf`| this takes an array of inputs and matches any of them. |
51
+
|`anyOf`| this takes a variable number of inputs and matches any of them. |
42
52
|`char`, `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `letter.lowercase`, `letter.uppercase`, `tab`, `linefeed` and `carriageReturn`| these are helpers for specific RegExp characters. |
43
53
|`not`| this can prefix `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `letter.lowercase`, `letter.uppercase`, `tab`, `linefeed` or `carriageReturn`. For example `createRegExp(not.letter)`. |
44
-
|`maybe`| equivalent to `?` - this marks the input as optional. |
45
-
|`oneOrMore`| Equivalent to `+` - this marks the input as repeatable, any number of times but at least once. |
46
-
|`exactly`| This escapes a string input to match it exactly. |
54
+
|`maybe`| equivalent to `?` - this takes a variable number of inputs and marks them as optional. |
55
+
|`oneOrMore`| Equivalent to `+` - this takes a variable number of inputs and marks them as repeatable, any number of times but at least once. |
56
+
|`exactly`| This takes a variable number of inputs and concatenate their patterns, and escapes string inputs to match it exactly. |
57
+
58
+
::alert
59
+
All helpers that takes `string` and `Input` are variadic functions, so you can pass in one or multiple arguments of `string` or `Input` to them and they will be concatenated to one pattern. for example,s `exactly('foo', maybe('bar'))` is equivalent to `exactly('foo').and(maybe('bar'))`.
60
+
::
47
61
48
62
## Chaining inputs
49
63
50
64
All of the helpers above return an object of type `Input` that can be chained with the following helpers:
|`and`| this adds a new pattern to the current input, or you can use `and.referenceTo(groupName)` to adds a new pattern referencing to a named group. |
55
-
|`or`| this provides an alternative to the current input. |
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). |
68
+
|`and`| this takes a variable number of inputs and adds them as new pattern to the current input, or you can use `and.referenceTo(groupName)` to adds a new pattern referencing to a named group. |
69
+
|`or`| this takes a variable number of inputs and provides as an alternative to the current input. |
70
+
|`after`, `before`, `notAfter` and `notBefore`| these takes a variable number of inputs and 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
71
|`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(x)` to indicate it must repeat at least x times, `times.atMost(x)` to indicate it must repeat at most x times or `times.any()` to indicate it can repeat any number of times, _including none_. |
58
72
|`optionally`| this is a function you can call to mark the current input as optional. |
0 commit comments