rregex 1.10.7 → 1.10.9
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 +9 -9
- package/lib/{bundler.d.ts → cf.d.ts} +70 -0
- package/lib/{bundler.mjs → cf.mjs} +7 -4
- package/lib/commonjs.d.ts +12 -0
- package/lib/rregex.wasm +0 -0
- package/lib/standalone.d.ts +12 -0
- package/lib/types.d.ts +1 -0
- package/lib/web.d.ts +1321 -0
- package/package.json +1 -1
- package/lib/bundler_bg.mjs +0 -1213
package/lib/web.d.ts
ADDED
|
@@ -0,0 +1,1321 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Escapes all regular expression meta characters in `text`.
|
|
5
|
+
*
|
|
6
|
+
* The string returned may be safely used as a literal in a regular
|
|
7
|
+
* expression.
|
|
8
|
+
* @param {string} text
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function escape(text: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Represents a single match of a regex in a haystack.
|
|
14
|
+
*
|
|
15
|
+
* A `Match` contains both the start and end byte offsets of the match and the
|
|
16
|
+
* actual substring corresponding to the range of those byte offsets. It is
|
|
17
|
+
* guaranteed that `start <= end`. When `start == end`, the match is empty.
|
|
18
|
+
*
|
|
19
|
+
* Since this `Match` can only be produced by the top-level `Regex` APIs
|
|
20
|
+
* that only support searching UTF-8 encoded strings, the byte offsets for a
|
|
21
|
+
* `Match` are guaranteed to fall on valid UTF-8 codepoint boundaries. That
|
|
22
|
+
* is, slicing an `Uint8Array` created with a TextEncoder is guaranteed to never
|
|
23
|
+
* be out of range.
|
|
24
|
+
*
|
|
25
|
+
* # Numbering
|
|
26
|
+
*
|
|
27
|
+
* The byte offsets in a `Match` form a half-open interval. That is, the
|
|
28
|
+
* start of the range is inclusive and the end of the range is exclusive.
|
|
29
|
+
* For example, given a haystack `abcFOOxyz` and a match of `FOO`, its byte
|
|
30
|
+
* offset range starts at `3` and ends at `6`. `3` corresponds to `F` and
|
|
31
|
+
* `6` corresponds to `x`, which is one past the end of the match. This
|
|
32
|
+
* corresponds to the same kind of slicing that Rust uses.
|
|
33
|
+
*
|
|
34
|
+
* For more on why this was chosen over other schemes (aside from being
|
|
35
|
+
* consistent with how Rust the language works), see [this discussion] and
|
|
36
|
+
* [Dijkstra's note on a related topic][note].
|
|
37
|
+
*
|
|
38
|
+
* [this discussion]: https://github.com/rust-lang/regex/discussions/866
|
|
39
|
+
* [note]: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
|
|
40
|
+
*
|
|
41
|
+
* # Example
|
|
42
|
+
*
|
|
43
|
+
* This example shows the value of each of the methods on `Match` for a
|
|
44
|
+
* particular search.
|
|
45
|
+
*
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { RRegex } from "rregex"
|
|
48
|
+
*
|
|
49
|
+
* const re = new RRegex("\\p{Greek}+");
|
|
50
|
+
* const hay = "Greek: αβγδ";
|
|
51
|
+
* const m = re.find(hay);
|
|
52
|
+
* expect(m.start).toBe(7);
|
|
53
|
+
* expect(m.end).toBe(15);
|
|
54
|
+
* expect(m.value).toBe("αβγδ");
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @see @see https://docs.rs/regex/latest/regex/
|
|
58
|
+
*/
|
|
59
|
+
export type Match = {
|
|
60
|
+
start: number
|
|
61
|
+
end: number
|
|
62
|
+
value: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Represents the capture groups for a single match.
|
|
67
|
+
*
|
|
68
|
+
* Capture groups refer to parts of a regex enclosed in parentheses. They can
|
|
69
|
+
* be optionally named. The purpose of capture groups is to be able to
|
|
70
|
+
* reference different parts of a match based on the original pattern. For
|
|
71
|
+
* example, say you want to match the individual letters in a 5-letter word:
|
|
72
|
+
*
|
|
73
|
+
* ```text
|
|
74
|
+
* (?<first>\w)(\w)(?:\w)\w(?<last>\w)
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* This regex has 4 capture groups:
|
|
78
|
+
*
|
|
79
|
+
* * The group at index `0` corresponds to the overall match. It is always
|
|
80
|
+
* present in every match and never has a name.
|
|
81
|
+
* * The group at index `1` with name `first` corresponding to the first
|
|
82
|
+
* letter.
|
|
83
|
+
* * The group at index `2` with no name corresponding to the second letter.
|
|
84
|
+
* * The group at index `3` with name `last` corresponding to the fifth and
|
|
85
|
+
* last letter.
|
|
86
|
+
*
|
|
87
|
+
* Notice that `(?:\w)` was not listed above as a capture group despite it
|
|
88
|
+
* being enclosed in parentheses. That's because `(?:pattern)` is a special
|
|
89
|
+
* syntax that permits grouping but *without* capturing. The reason for not
|
|
90
|
+
* treating it as a capture is that tracking and reporting capture groups
|
|
91
|
+
* requires additional state that may lead to slower searches. So using as few
|
|
92
|
+
* capture groups as possible can help performance. (Although the difference
|
|
93
|
+
* in performance of a couple of capture groups is likely immaterial.)
|
|
94
|
+
*
|
|
95
|
+
* # Example
|
|
96
|
+
*
|
|
97
|
+
* ```typescript
|
|
98
|
+
* import { RRegex } from "rregex"
|
|
99
|
+
*
|
|
100
|
+
* const re = new RRegex("(?<first>\\w)(\\w)(?:\\w)\\w(?<last>\\w)");
|
|
101
|
+
* const caps = re.captures("toady");
|
|
102
|
+
* expect(caps.get[0].value).toBe("toady");
|
|
103
|
+
* expect(caps.name["first"].value).toBe("t");
|
|
104
|
+
* expect(caps.get[2].value).toBe("o");
|
|
105
|
+
* expect(caps.name["last"].value).toBe("y");
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export type Captures = {
|
|
109
|
+
get: Match[]
|
|
110
|
+
name: Record<string, Match>
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A high-level intermediate representation (HIR) for a regular expression.
|
|
115
|
+
*/
|
|
116
|
+
export type Hir = {
|
|
117
|
+
'@type': 'struct'
|
|
118
|
+
'@name': 'regex_syntax::hir::Hir'
|
|
119
|
+
kind: HirKind
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The underlying kind of an arbitrary `Hir` expression.
|
|
124
|
+
*
|
|
125
|
+
* An `HirKind` is principally useful for doing case analysis on the type of a
|
|
126
|
+
* regular expression. If you're looking to build new `Hir` values, then you must
|
|
127
|
+
* use the smart constructors defined on `Hir`, like `Hir::repetition`, to build
|
|
128
|
+
* new `Hir` values. The API intentionally does not expose any way of building an
|
|
129
|
+
* `Hir` directly from an `HirKind`.
|
|
130
|
+
*/
|
|
131
|
+
export type HirKind =
|
|
132
|
+
| HirKindEmptyVariant
|
|
133
|
+
| HirKindLiteralVariant
|
|
134
|
+
| HirKindClassVariant
|
|
135
|
+
| HirKindLookVariant
|
|
136
|
+
| HirKindRepetitionVariant
|
|
137
|
+
| HirKindCaptureVariant
|
|
138
|
+
| HirKindConcatVariant
|
|
139
|
+
| HirKindAlternationVariant
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The empty regular expression, which matches everything, including the empty string.
|
|
143
|
+
*/
|
|
144
|
+
export type HirKindEmptyVariant = {
|
|
145
|
+
'@type': 'enum'
|
|
146
|
+
'@name': 'regex_syntax::hir::HirKind'
|
|
147
|
+
'@variant': 'Empty'
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A literal string that matches exactly these bytes.
|
|
152
|
+
*/
|
|
153
|
+
export type HirKindLiteralVariant = {
|
|
154
|
+
'@type': 'enum'
|
|
155
|
+
'@name': 'regex_syntax::hir::HirKind'
|
|
156
|
+
'@variant': 'Literal'
|
|
157
|
+
'@values': [Literal]
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* A single character class that matches any of the characters in the class.
|
|
162
|
+
* A class can either consist of Unicode scalar values as characters, or it can
|
|
163
|
+
* use bytes.
|
|
164
|
+
*
|
|
165
|
+
* A class may be empty. In which case, it matches nothing.
|
|
166
|
+
*/
|
|
167
|
+
export type HirKindClassVariant = {
|
|
168
|
+
'@type': 'enum'
|
|
169
|
+
'@name': 'regex_syntax::hir::HirKind'
|
|
170
|
+
'@variant': 'Class'
|
|
171
|
+
'@values': [Class]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A look-around assertion. A look-around match always has zero length.
|
|
176
|
+
*/
|
|
177
|
+
export type HirKindLookVariant = {
|
|
178
|
+
'@type': 'enum'
|
|
179
|
+
'@name': 'regex_syntax::hir::HirKind'
|
|
180
|
+
'@variant': 'Look'
|
|
181
|
+
'@values': [Look]
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* A repetition operation applied to a sub-expression.
|
|
186
|
+
*/
|
|
187
|
+
export type HirKindRepetitionVariant = {
|
|
188
|
+
'@type': 'enum'
|
|
189
|
+
'@name': 'regex_syntax::hir::HirKind'
|
|
190
|
+
'@variant': 'Repetition'
|
|
191
|
+
'@values': [Repetition]
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A capturing group, which contains a sub-expression.
|
|
196
|
+
*/
|
|
197
|
+
export type HirKindCaptureVariant = {
|
|
198
|
+
'@type': 'enum'
|
|
199
|
+
'@name': 'regex_syntax::hir::HirKind'
|
|
200
|
+
'@variant': 'Capture'
|
|
201
|
+
'@values': [Capture]
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* A concatenation of expressions.
|
|
206
|
+
*
|
|
207
|
+
* A concatenation matches only if each of its sub-expressions match one after
|
|
208
|
+
* the other.
|
|
209
|
+
*
|
|
210
|
+
* Concatenations are guaranteed by `Hir`'s smart constructors to always have at
|
|
211
|
+
* least two sub-expressions.
|
|
212
|
+
*/
|
|
213
|
+
export type HirKindConcatVariant = {
|
|
214
|
+
'@type': 'enum'
|
|
215
|
+
'@name': 'regex_syntax::hir::HirKind'
|
|
216
|
+
'@variant': 'Concat'
|
|
217
|
+
'@values': [Hir[]]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* An alternation of expressions.
|
|
222
|
+
*
|
|
223
|
+
* An alternation matches only if at least one of its sub-expressions match.
|
|
224
|
+
* If multiple sub-expressions match, then the leftmost is preferred.
|
|
225
|
+
*
|
|
226
|
+
* Alternations are guaranteed by `Hir`'s smart constructors to always have at
|
|
227
|
+
* least two sub-expressions.
|
|
228
|
+
*/
|
|
229
|
+
export type HirKindAlternationVariant = {
|
|
230
|
+
'@type': 'enum'
|
|
231
|
+
'@name': 'regex_syntax::hir::HirKind'
|
|
232
|
+
'@variant': 'Alternation'
|
|
233
|
+
'@values': [Hir[]]
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The high-level intermediate representation of a literal.
|
|
238
|
+
*
|
|
239
|
+
* A literal corresponds to 0 or more bytes that should be matched literally.
|
|
240
|
+
* The smart constructors defined on `Hir` will automatically concatenate adjacent
|
|
241
|
+
* literals into one literal, and will even automatically replace empty literals
|
|
242
|
+
* with `HirKind::Empty`.
|
|
243
|
+
*/
|
|
244
|
+
export type Literal = {
|
|
245
|
+
'@type': 'struct'
|
|
246
|
+
'@name': 'regex_syntax::hir::Literal'
|
|
247
|
+
'@values': [Uint8Array]
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The high-level intermediate representation of a character class.
|
|
252
|
+
*
|
|
253
|
+
* A character class corresponds to a set of characters. A character is either
|
|
254
|
+
* defined by a Unicode scalar value or a byte. Unicode characters are used by
|
|
255
|
+
* default, while bytes are used when Unicode mode (via the `u` flag) is disabled.
|
|
256
|
+
*
|
|
257
|
+
* A character class, regardless of its character type, is represented by a
|
|
258
|
+
* sequence of non-overlapping non-adjacent ranges of characters.
|
|
259
|
+
*
|
|
260
|
+
* Note that `Bytes` variant may be produced even when it exclusively matches
|
|
261
|
+
* valid UTF-8. This is because a `Bytes` variant represents an intention by the
|
|
262
|
+
* author of the regular expression to disable Unicode mode, which in turn
|
|
263
|
+
* impacts the semantics of case insensitive matching. For example, `(?i)k` and
|
|
264
|
+
* `(?i-u)k` will not match the same set of strings.
|
|
265
|
+
*/
|
|
266
|
+
export type Class =
|
|
267
|
+
| ClassUnicodeVariant
|
|
268
|
+
| ClassByteVariant
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* A set of characters represented by Unicode scalar values.
|
|
272
|
+
*/
|
|
273
|
+
export type ClassUnicodeVariant = {
|
|
274
|
+
'@type': 'enum'
|
|
275
|
+
'@name': 'regex_syntax::hir::Class'
|
|
276
|
+
'@variant': 'Unicode'
|
|
277
|
+
'@values': [ClassUnicode]
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* A set of characters represented by arbitrary bytes (one byte per character).
|
|
282
|
+
*/
|
|
283
|
+
export type ClassByteVariant = {
|
|
284
|
+
'@type': 'enum'
|
|
285
|
+
'@name': 'regex_syntax::hir::Class'
|
|
286
|
+
'@variant': 'Bytes'
|
|
287
|
+
'@values': [ClassBytes]
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* A set of characters represented by Unicode scalar values.
|
|
292
|
+
*/
|
|
293
|
+
export type ClassUnicode = {
|
|
294
|
+
'@type': 'struct'
|
|
295
|
+
'@name': 'regex_syntax::hir::ClassUnicode'
|
|
296
|
+
|
|
297
|
+
/** The underlying ranges as a slice. */
|
|
298
|
+
ranges: ClassUnicodeRange[]
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A single range of characters represented by Unicode scalar values.
|
|
303
|
+
*
|
|
304
|
+
* The range is closed. That is, the start and end of the range are included in
|
|
305
|
+
* the range.
|
|
306
|
+
*/
|
|
307
|
+
export type ClassUnicodeRange = {
|
|
308
|
+
'@type': 'struct'
|
|
309
|
+
'@name': 'regex_syntax::hir::ClassUnicodeRange'
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Return the start of this range.
|
|
313
|
+
*
|
|
314
|
+
* The start of a range is always less than or equal to the end of the range.
|
|
315
|
+
*/
|
|
316
|
+
start: string
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Return the end of this range.
|
|
320
|
+
*
|
|
321
|
+
* The end of a range is always greater than or equal to the start of the range.
|
|
322
|
+
*/
|
|
323
|
+
end: string
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The number of codepoints in this range.
|
|
327
|
+
*/
|
|
328
|
+
len: number
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* A set of characters represented by arbitrary bytes (where one byte corresponds
|
|
333
|
+
* to one character).
|
|
334
|
+
*/
|
|
335
|
+
export type ClassBytes = {
|
|
336
|
+
'@type': 'struct'
|
|
337
|
+
'@name': 'regex_syntax::hir::ClassBytes'
|
|
338
|
+
|
|
339
|
+
/** The underlying ranges as a slice. */
|
|
340
|
+
ranges: ClassBytesRange[]
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* A single range of characters represented by arbitrary bytes.
|
|
345
|
+
*
|
|
346
|
+
* The range is closed. That is, the start and end of the range are included in
|
|
347
|
+
* the range.
|
|
348
|
+
*/
|
|
349
|
+
export type ClassBytesRange = {
|
|
350
|
+
'@type': 'struct'
|
|
351
|
+
'@name': 'regex_syntax::hir::ClassBytesRange'
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* The start of this range.
|
|
355
|
+
*
|
|
356
|
+
* The start of a range is always less than or equal to the end of the range.
|
|
357
|
+
*/
|
|
358
|
+
start: number
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The end of this range.
|
|
362
|
+
*
|
|
363
|
+
* The end of a range is always greater than or equal to the start of the range.
|
|
364
|
+
*/
|
|
365
|
+
end: number
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* The number of bytes in this range.
|
|
369
|
+
*/
|
|
370
|
+
len: number
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The high-level intermediate representation for a look-around assertion.
|
|
375
|
+
*
|
|
376
|
+
* An assertion match is always zero-length. Also called an “empty match.”
|
|
377
|
+
*/
|
|
378
|
+
export type Look =
|
|
379
|
+
| LookStartVariant
|
|
380
|
+
| LookEndVariant
|
|
381
|
+
| LookStartLFVariant
|
|
382
|
+
| LookEndLFVariant
|
|
383
|
+
| LookStartCRLFVariant
|
|
384
|
+
| LookEndCRLFVariant
|
|
385
|
+
| LookWordAsciiVariant
|
|
386
|
+
| LookWordAsciiNegateVariant
|
|
387
|
+
| LookWordUnicodeVariant
|
|
388
|
+
| LookWordUnicodeNegateVariant
|
|
389
|
+
| LookWordStartAsciiVariant
|
|
390
|
+
| LookWordEndAsciiVariant
|
|
391
|
+
| LookWordStartUnicodeVariant
|
|
392
|
+
| LookWordEndUnicodeVariant
|
|
393
|
+
| LookWordStartHalfAsciiVariant
|
|
394
|
+
| LookWordEndHalfAsciiVariant
|
|
395
|
+
| LookWordStartHalfUnicodeVariant
|
|
396
|
+
| LookWordEndHalfUnicodeVariant
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Match the beginning of text. Specifically, this matches at the starting
|
|
400
|
+
* position of the input.
|
|
401
|
+
*/
|
|
402
|
+
export type LookStartVariant = {
|
|
403
|
+
'@type': 'enum'
|
|
404
|
+
'@name': 'regex_syntax::hir:Look'
|
|
405
|
+
'@variant': 'Start'
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Match the end of text. Specifically, this matches at the ending position of
|
|
410
|
+
* the input.
|
|
411
|
+
*/
|
|
412
|
+
export type LookEndVariant = {
|
|
413
|
+
'@type': 'enum'
|
|
414
|
+
'@name': 'regex_syntax::hir:Look'
|
|
415
|
+
'@variant': 'End'
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Match the beginning of a line or the beginning of text. Specifically, this
|
|
420
|
+
* matches at the starting position of the input, or at the position immediately
|
|
421
|
+
* following a `\n` character.
|
|
422
|
+
*/
|
|
423
|
+
export type LookStartLFVariant = {
|
|
424
|
+
'@type': 'enum'
|
|
425
|
+
'@name': 'regex_syntax::hir:Look'
|
|
426
|
+
'@variant': 'StartLF'
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Match the end of a line or the end of text. Specifically, this matches at the
|
|
431
|
+
* end position of the input, or at the position immediately preceding a `\n`
|
|
432
|
+
* character.
|
|
433
|
+
*/
|
|
434
|
+
export type LookEndLFVariant = {
|
|
435
|
+
'@type': 'enum'
|
|
436
|
+
'@name': 'regex_syntax::hir:Look'
|
|
437
|
+
'@variant': 'EndLF'
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Match the beginning of a line or the beginning of text. Specifically, this
|
|
442
|
+
* matches at the starting position of the input, or at the position immediately
|
|
443
|
+
* following either a `\r` or `\n` character, but never after a `\r` when a `\n`
|
|
444
|
+
* follows.
|
|
445
|
+
*/
|
|
446
|
+
export type LookStartCRLFVariant = {
|
|
447
|
+
'@type': 'enum'
|
|
448
|
+
'@name': 'regex_syntax::hir:Look'
|
|
449
|
+
'@variant': 'StartCRLF'
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Match the end of a line or the end of text. Specifically, this matches at the
|
|
454
|
+
* end position of the input, or at the position immediately preceding a `\r` or
|
|
455
|
+
* `\n` character, but never before a `\n` when a `\r` precedes it.
|
|
456
|
+
*/
|
|
457
|
+
export type LookEndCRLFVariant = {
|
|
458
|
+
'@type': 'enum'
|
|
459
|
+
'@name': 'regex_syntax::hir:Look'
|
|
460
|
+
'@variant': 'EndCRLF'
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Match an ASCII-only word boundary. That is, this matches a position where the
|
|
465
|
+
* left adjacent character and right adjacent character correspond to a word and
|
|
466
|
+
* non-word or a non-word and word character.
|
|
467
|
+
*/
|
|
468
|
+
export type LookWordAsciiVariant = {
|
|
469
|
+
'@type': 'enum'
|
|
470
|
+
'@name': 'regex_syntax::hir:Look'
|
|
471
|
+
'@variant': 'WordAscii'
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Match an ASCII-only negation of a word boundary.
|
|
476
|
+
*/
|
|
477
|
+
export type LookWordAsciiNegateVariant = {
|
|
478
|
+
'@type': 'enum'
|
|
479
|
+
'@name': 'regex_syntax::hir:Look'
|
|
480
|
+
'@variant': 'WordAsciiNegate'
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Match a Unicode-aware word boundary. That is, this matches a position where
|
|
485
|
+
* the left adjacent character and right adjacent character correspond to a word
|
|
486
|
+
* and non-word or a non-word and word character.
|
|
487
|
+
*/
|
|
488
|
+
export type LookWordUnicodeVariant = {
|
|
489
|
+
'@type': 'enum'
|
|
490
|
+
'@name': 'regex_syntax::hir:Look'
|
|
491
|
+
'@variant': 'WordUnicode'
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Match a Unicode-aware negation of a word boundary.
|
|
496
|
+
*/
|
|
497
|
+
export type LookWordUnicodeNegateVariant = {
|
|
498
|
+
'@type': 'enum'
|
|
499
|
+
'@name': 'regex_syntax::hir:Look'
|
|
500
|
+
'@variant': 'WordUnicodeNegate'
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Match the start of an ASCII-only word boundary. That is, this matches a
|
|
505
|
+
* position at either the beginning of the haystack or where the previous
|
|
506
|
+
* character is not a word character and the following character is a word
|
|
507
|
+
* character.
|
|
508
|
+
*/
|
|
509
|
+
export type LookWordStartAsciiVariant = {
|
|
510
|
+
'@type': 'enum'
|
|
511
|
+
'@name': 'regex_syntax::hir:Look'
|
|
512
|
+
'@variant': 'WordStartAscii'
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Match the end of an ASCII-only word boundary. That is, this matches a
|
|
517
|
+
* position at either the end of the haystack orwhere the previous character is
|
|
518
|
+
* a word character and the following character is not a word character.
|
|
519
|
+
*/
|
|
520
|
+
export type LookWordEndAsciiVariant = {
|
|
521
|
+
'@type': 'enum'
|
|
522
|
+
'@name': 'regex_syntax::hir:Look'
|
|
523
|
+
'@variant': 'WordEndAscii'
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Match the start of a Unicode word boundary. That is, this matches a position
|
|
528
|
+
* at either the beginning of the haystack or where the previous character is
|
|
529
|
+
* not a word character and the following character is a word character.
|
|
530
|
+
*/
|
|
531
|
+
export type LookWordStartUnicodeVariant = {
|
|
532
|
+
'@type': 'enum'
|
|
533
|
+
'@name': 'regex_syntax::hir:Look'
|
|
534
|
+
'@variant': 'WordStartUnicode'
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Match the end of a Unicode word boundary. That is, this matches a position at
|
|
539
|
+
* either the end of the haystack or where the previous character is a word
|
|
540
|
+
* character and the following character is not a word character.
|
|
541
|
+
*/
|
|
542
|
+
export type LookWordEndUnicodeVariant = {
|
|
543
|
+
'@type': 'enum'
|
|
544
|
+
'@name': 'regex_syntax::hir:Look'
|
|
545
|
+
'@variant': 'WordEndUnicode'
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Match the start half of an ASCII-only word boundary. That is, this matches a
|
|
550
|
+
* position at either the beginning of the haystack or where the previous
|
|
551
|
+
* character is not a word character.
|
|
552
|
+
*/
|
|
553
|
+
export type LookWordStartHalfAsciiVariant = {
|
|
554
|
+
'@type': 'enum'
|
|
555
|
+
'@name': 'regex_syntax::hir::Look',
|
|
556
|
+
'@variant': 'WordStartHalfAscii'
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Match the end half of an ASCII-only word boundary. That is, this matches a
|
|
561
|
+
* position at either the end of the haystack or where the following character
|
|
562
|
+
* is not a word character.
|
|
563
|
+
*/
|
|
564
|
+
export type LookWordEndHalfAsciiVariant = {
|
|
565
|
+
'@type': 'enum'
|
|
566
|
+
'@name': 'regex_syntax::hir::Look',
|
|
567
|
+
'@variant': 'WordEndHalfAscii'
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Match the start half of a Unicode word boundary. That is, this matches a
|
|
572
|
+
* position at either the beginning of the haystack or where the previous
|
|
573
|
+
* character is not a word character.
|
|
574
|
+
*/
|
|
575
|
+
export type LookWordStartHalfUnicodeVariant = {
|
|
576
|
+
'@type': 'enum'
|
|
577
|
+
'@name': 'regex_syntax::hir::Look',
|
|
578
|
+
'@variant': 'WordStartHalfUnicode'
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Match the end half of a Unicode word boundary. That is, this matches a
|
|
583
|
+
* position at either the end of the haystack or where the following character
|
|
584
|
+
* is not a word character.
|
|
585
|
+
*/
|
|
586
|
+
export type LookWordEndHalfUnicodeVariant = {
|
|
587
|
+
'@type': 'enum'
|
|
588
|
+
'@name': 'regex_syntax::hir::Look',
|
|
589
|
+
'@variant': 'WordEndHalfUnicode'
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* The high-level intermediate representation of a repetition operator.
|
|
594
|
+
*
|
|
595
|
+
* A repetition operator permits the repetition of an arbitrary sub-expression
|
|
596
|
+
*/
|
|
597
|
+
export type Repetition = {
|
|
598
|
+
'@type': 'struct'
|
|
599
|
+
'@name': 'regex_syntax::hir::Repetition'
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* The minimum range of the repetition.
|
|
603
|
+
*
|
|
604
|
+
* Note that special cases like `?`, `+` and `*` all get translated into the
|
|
605
|
+
* ranges `{0,1}`, `{1,}` and `{0,}`, respectively.
|
|
606
|
+
*
|
|
607
|
+
* When `min` is zero, this expression can match the empty string regardless
|
|
608
|
+
* of what its sub-expression is.
|
|
609
|
+
*/
|
|
610
|
+
min: number
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* The maximum range of the repetition.
|
|
614
|
+
*
|
|
615
|
+
* Note that when `max` is `undefined`, `min` acts as a lower bound but where
|
|
616
|
+
* there is no upper bound. For something like `x{5}` where the min and max
|
|
617
|
+
* are equivalent, `min` will be set to `5` and `max` will be set to `5`.
|
|
618
|
+
*/
|
|
619
|
+
max?: number
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Whether this repetition operator is greedy or not. A greedy operator will
|
|
623
|
+
* match as much as it can. A non-greedy operator will match as little as it
|
|
624
|
+
* can.
|
|
625
|
+
*
|
|
626
|
+
* Typically, operators are greedy by default and are only non-greedy when a
|
|
627
|
+
* `?` suffix is used, e.g., `(expr)*` is greedy while `(expr)*?` is not.
|
|
628
|
+
* However, this can be inverted via the `U` “ungreedy” flag.
|
|
629
|
+
*/
|
|
630
|
+
greedy: boolean
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* The expression being repeated.
|
|
634
|
+
*/
|
|
635
|
+
sub: Hir
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* The high-level intermediate representation for a capturing group.
|
|
640
|
+
*
|
|
641
|
+
* A capturing group always has an index and a child expression. It may also
|
|
642
|
+
* have a name associated with it (e.g., `(?P<foo>\w)`), but it's not necessary.
|
|
643
|
+
*
|
|
644
|
+
* Note that there is no explicit representation of a non-capturing group in a
|
|
645
|
+
* `Hir`. Instead, non-capturing grouping is handled automatically by the
|
|
646
|
+
* recursive structure of the `Hir` itself.
|
|
647
|
+
*/
|
|
648
|
+
export type Capture = {
|
|
649
|
+
'@type': 'struct'
|
|
650
|
+
'@name': 'regex_syntax::hir::Capture'
|
|
651
|
+
|
|
652
|
+
/** The capture index of the capture. */
|
|
653
|
+
index: number
|
|
654
|
+
|
|
655
|
+
/** The name of the capture, if it exists. */
|
|
656
|
+
name?: String
|
|
657
|
+
|
|
658
|
+
/** The expression inside the capturing group, which may be empty. */
|
|
659
|
+
sub: Hir
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* A compiled regular expression for matching Unicode strings.
|
|
664
|
+
*
|
|
665
|
+
* A `RRegex` can be used to search haystacks, split haystacks into substrings
|
|
666
|
+
* or replace substrings in a haystack with a different substring. All
|
|
667
|
+
* searching is done with an implicit `(?s:.)*?` at the beginning and end of
|
|
668
|
+
* an pattern. To force an expression to match the whole string (or a prefix
|
|
669
|
+
* or a suffix), you must use an anchor like `^` or `$` (or `\A` and `\z`).
|
|
670
|
+
*
|
|
671
|
+
* While this library will handle Unicode strings (whether in the regular
|
|
672
|
+
* expression or in the haystack), all positions returned are **byte
|
|
673
|
+
* offsets**. Every byte offset is guaranteed to be at a Unicode code point
|
|
674
|
+
* boundary. That is, all offsets returned by the `RRegex` API are guaranteed
|
|
675
|
+
* to be ranges that can slice an `Uint8Array` created with a TextEncoder.
|
|
676
|
+
*
|
|
677
|
+
* # Example: slicing over UTF strings
|
|
678
|
+
*
|
|
679
|
+
* ```typescript
|
|
680
|
+
* import { RRegex } from "rregex"
|
|
681
|
+
*
|
|
682
|
+
* const re = new RRegex("ä")
|
|
683
|
+
* const m = re.find("äöü") // { start: 0, end: 2 }
|
|
684
|
+
*
|
|
685
|
+
* const buff = new TextEncoder().encode("äöü")
|
|
686
|
+
* const slice = buff.slice(m.start, m.end)
|
|
687
|
+
* expect(new TextDecoder().decode(slice)).toBe("ä")
|
|
688
|
+
* ```
|
|
689
|
+
*
|
|
690
|
+
* # Example: find the offsets of a US phone number:
|
|
691
|
+
*
|
|
692
|
+
* ```typescript
|
|
693
|
+
* import { RRegex } from "rregex"
|
|
694
|
+
*
|
|
695
|
+
* const re = new RRegex("[0-9]{3}-[0-9]{3}-[0-9]{4}");
|
|
696
|
+
* const m = re.find("phone: 111-222-3333");
|
|
697
|
+
* expect(m.start).toBe(7);
|
|
698
|
+
* expect(m.end).toBe(19);
|
|
699
|
+
* ```
|
|
700
|
+
*
|
|
701
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
702
|
+
*/
|
|
703
|
+
export class RRegex {
|
|
704
|
+
free(): void;
|
|
705
|
+
/**
|
|
706
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
707
|
+
* to search, split or replace text in a string.
|
|
708
|
+
*
|
|
709
|
+
* If an invalid expression is given, then an error is returned.
|
|
710
|
+
* @param {string} re
|
|
711
|
+
*/
|
|
712
|
+
constructor(re: string);
|
|
713
|
+
/**
|
|
714
|
+
* Returns true if and only if there is a match for the regex in the
|
|
715
|
+
* string given.
|
|
716
|
+
*
|
|
717
|
+
* It is recommended to use this method if all you need to do is test
|
|
718
|
+
* a match, since the underlying matching engine may be able to do less
|
|
719
|
+
* work.
|
|
720
|
+
*
|
|
721
|
+
* # Example
|
|
722
|
+
*
|
|
723
|
+
* Test if some text contains at least one word with exactly 13
|
|
724
|
+
* Unicode word characters:
|
|
725
|
+
*
|
|
726
|
+
* ```typescript
|
|
727
|
+
* import { RRegex } from "rregex"
|
|
728
|
+
*
|
|
729
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
730
|
+
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
731
|
+
* ```
|
|
732
|
+
*
|
|
733
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
734
|
+
* @param {string} text - The string against which to match the regular expression
|
|
735
|
+
* @return {boolean}
|
|
736
|
+
*/
|
|
737
|
+
isMatch(text: string): boolean;
|
|
738
|
+
/**
|
|
739
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
740
|
+
* The significance of the starting point is that it takes the surrounding
|
|
741
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
742
|
+
* when `start == 0`.
|
|
743
|
+
*
|
|
744
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
745
|
+
* @param {string} text - The string against which to match the regular expression
|
|
746
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
747
|
+
* @return {boolean}
|
|
748
|
+
*/
|
|
749
|
+
isMatchAt(text: string, start: number): boolean;
|
|
750
|
+
/**
|
|
751
|
+
* Returns the start and end byte range of the leftmost-first match in
|
|
752
|
+
* `text`. If no match exists, then `undefined` is returned.
|
|
753
|
+
*
|
|
754
|
+
* Note that this should only be used if you want to discover the position
|
|
755
|
+
* of the match. Testing the existence of a match is faster if you use
|
|
756
|
+
* `isMatch`.
|
|
757
|
+
*
|
|
758
|
+
* # Example
|
|
759
|
+
*
|
|
760
|
+
* Find the start and end location of the first word with exactly 13
|
|
761
|
+
* Unicode word characters:
|
|
762
|
+
*
|
|
763
|
+
* ```typescript
|
|
764
|
+
* import { RRegex } from "rregex"
|
|
765
|
+
*
|
|
766
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
767
|
+
* const m = new RRegex("\\b\\w{13}\\b").find(text)
|
|
768
|
+
* expect(m.start).toBe(2)
|
|
769
|
+
* expect(m.end).toBe(15)
|
|
770
|
+
* ```
|
|
771
|
+
*
|
|
772
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
773
|
+
* @param {string} text - The string against which to match the regular expression
|
|
774
|
+
* @return {Match}
|
|
775
|
+
*/
|
|
776
|
+
find(text: string): Match | undefined;
|
|
777
|
+
/**
|
|
778
|
+
* Returns the same as find, but starts the search at the given
|
|
779
|
+
* offset.
|
|
780
|
+
*
|
|
781
|
+
* The significance of the starting point is that it takes the surrounding
|
|
782
|
+
* context into consideration. For example, the `\A` anchor can only
|
|
783
|
+
* match when `start == 0`.
|
|
784
|
+
*
|
|
785
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
786
|
+
* @param {string} text - The string against which to match the regular expression
|
|
787
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
788
|
+
* @returns {Match}
|
|
789
|
+
*/
|
|
790
|
+
findAt(text: string, start: number): Match | undefined;
|
|
791
|
+
/**
|
|
792
|
+
* Returns an array for each successive non-overlapping match in `text``,
|
|
793
|
+
* returning the start and end byte indices with respect to `text`.
|
|
794
|
+
*
|
|
795
|
+
* # Example
|
|
796
|
+
*
|
|
797
|
+
* Find the start and end location of every word with exactly 13 Unicode
|
|
798
|
+
* word characters:
|
|
799
|
+
*
|
|
800
|
+
* ```typescript
|
|
801
|
+
* import { RRegex } from "rregex"
|
|
802
|
+
*
|
|
803
|
+
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
804
|
+
* const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
|
|
805
|
+
* ```
|
|
806
|
+
*
|
|
807
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
808
|
+
* @param {string} text - The string against which to match the regular expression
|
|
809
|
+
* @returns {Match}
|
|
810
|
+
*/
|
|
811
|
+
findAll(text: string): Match[];
|
|
812
|
+
/**
|
|
813
|
+
* Returns a list of the capture names in this regex.
|
|
814
|
+
*
|
|
815
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
816
|
+
*/
|
|
817
|
+
captureNames(): (string | null)[];
|
|
818
|
+
/**
|
|
819
|
+
* Returns the capture groups corresponding to the leftmost-first
|
|
820
|
+
* match in `text`. Capture group `0` always corresponds to the entire
|
|
821
|
+
* match. If no match is found, then `undefined` is returned.
|
|
822
|
+
*
|
|
823
|
+
* You should only use `captures` if you need access to the location of
|
|
824
|
+
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
825
|
+
* the location of the overall match.
|
|
826
|
+
*
|
|
827
|
+
* # Examples
|
|
828
|
+
*
|
|
829
|
+
* Say you have some text with movie names and their release years,
|
|
830
|
+
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
831
|
+
* looking like that, while also extracting the movie name and its release
|
|
832
|
+
* year separately.
|
|
833
|
+
*
|
|
834
|
+
* ```typescript
|
|
835
|
+
* import { RRegex } from "rregex"
|
|
836
|
+
*
|
|
837
|
+
* const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
838
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
839
|
+
* const caps = re.captures(text)
|
|
840
|
+
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
841
|
+
* expect(caps.get[2].value).toBe("1941")
|
|
842
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
843
|
+
* ```
|
|
844
|
+
*
|
|
845
|
+
* Note that the full match is at capture group `0`. Each subsequent
|
|
846
|
+
* capture group is indexed by the order of its opening `(`.
|
|
847
|
+
*
|
|
848
|
+
* We can make this example a bit clearer by using *named* capture groups:
|
|
849
|
+
*
|
|
850
|
+
* ```typescript
|
|
851
|
+
* import { RRegex } from "rregex"
|
|
852
|
+
*
|
|
853
|
+
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
854
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
855
|
+
* const caps = re.captures(text)
|
|
856
|
+
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
857
|
+
* expect(caps.name["year"].value).toBe("1941")
|
|
858
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
859
|
+
* ```
|
|
860
|
+
*
|
|
861
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
862
|
+
* @param {string} text - The string against which to match the regular expression
|
|
863
|
+
* @returns {Captures|undefined}
|
|
864
|
+
*/
|
|
865
|
+
captures(text: string): Captures | undefined;
|
|
866
|
+
/**
|
|
867
|
+
* Returns a list with all the non-overlapping capture groups matched
|
|
868
|
+
* in `text`. This is operationally the same as `findAll`, except it
|
|
869
|
+
* returns information about capturing group matches.
|
|
870
|
+
*
|
|
871
|
+
* # Example
|
|
872
|
+
*
|
|
873
|
+
* We can use this to find all movie titles and their release years in
|
|
874
|
+
* some text, where the movie is formatted like "'Title' (xxxx)":
|
|
875
|
+
*
|
|
876
|
+
* ```typescript
|
|
877
|
+
* import { RRegex } from "rregex"
|
|
878
|
+
*
|
|
879
|
+
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
880
|
+
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
881
|
+
* for caps of re.captures_iter(text) {
|
|
882
|
+
* console.log(
|
|
883
|
+
* "Movie:", caps.name["title"].value, ","
|
|
884
|
+
* "Released:", caps.name["year"].value
|
|
885
|
+
* );
|
|
886
|
+
* }
|
|
887
|
+
* // Output:
|
|
888
|
+
* // Movie: Citizen Kane, Released: 1941
|
|
889
|
+
* // Movie: The Wizard of Oz, Released: 1939
|
|
890
|
+
* // Movie: M, Released: 1931
|
|
891
|
+
* ```
|
|
892
|
+
*
|
|
893
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
894
|
+
* @param {string} text - The string against which to match the regular expression
|
|
895
|
+
* @returns {Captures[]}
|
|
896
|
+
*/
|
|
897
|
+
capturesAll(text: string): Captures[];
|
|
898
|
+
/**
|
|
899
|
+
* Returns the number of captures.
|
|
900
|
+
*
|
|
901
|
+
* This includes all named and unnamed groups, including the implicit
|
|
902
|
+
* unnamed group that is always present and corresponds to the entire match.
|
|
903
|
+
*
|
|
904
|
+
* Since the implicit unnamed group is always included in this length, the
|
|
905
|
+
* length returned is guaranteed to be greater than zero.
|
|
906
|
+
*
|
|
907
|
+
* ## Example
|
|
908
|
+
*
|
|
909
|
+
* ```typescript
|
|
910
|
+
* import { RRegex } from "rregex"
|
|
911
|
+
*
|
|
912
|
+
* const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
|
|
913
|
+
* expect(re1.capturesLength()).toEqual(4)
|
|
914
|
+
*
|
|
915
|
+
* const re2 = new RRegex("foo")
|
|
916
|
+
* expect(re2.capturesLength()).toEqual(1)
|
|
917
|
+
*
|
|
918
|
+
* const re3 = new RRegex("(foo)")
|
|
919
|
+
* expect(re3.capturesLength()).toEqual(2)
|
|
920
|
+
*
|
|
921
|
+
* const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
|
|
922
|
+
* expect(re4.capturesLength()).toEqual(5)
|
|
923
|
+
*
|
|
924
|
+
* const re5 = new RRegex("[a&&b]")
|
|
925
|
+
* expect(re5.capturesLength()).toEqual(1)
|
|
926
|
+
* ```
|
|
927
|
+
*
|
|
928
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
|
|
929
|
+
* @returns {number}
|
|
930
|
+
*/
|
|
931
|
+
capturesLength(): number;
|
|
932
|
+
/**
|
|
933
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
934
|
+
* The replacement can be a regular string (where `$N` and `$name` are
|
|
935
|
+
* expanded to match capture groups) or a function that takes the matches'
|
|
936
|
+
* `Captures` and returns the replaced string.
|
|
937
|
+
*
|
|
938
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
939
|
+
*
|
|
940
|
+
* # Replacement string syntax
|
|
941
|
+
*
|
|
942
|
+
* All instances of `$name` in the replacement text is replaced with the
|
|
943
|
+
* corresponding capture group `name`.
|
|
944
|
+
*
|
|
945
|
+
* `name` may be an integer corresponding to the index of the
|
|
946
|
+
* capture group (counted by order of opening parenthesis where `0` is the
|
|
947
|
+
* entire match) or it can be a name (consisting of letters, digits or
|
|
948
|
+
* underscores) corresponding to a named capture group.
|
|
949
|
+
*
|
|
950
|
+
* If `name` isn't a valid capture group (whether the name doesn't exist
|
|
951
|
+
* or isn't a valid index), then it is replaced with the empty string.
|
|
952
|
+
*
|
|
953
|
+
* The longest possible name is used. e.g., `$1a` looks up the capture
|
|
954
|
+
* group named `1a` and not the capture group at index `1`. To exert more
|
|
955
|
+
* precise control over the name, use braces, e.g., `${1}a`.
|
|
956
|
+
*
|
|
957
|
+
* To write a literal `$` use `$$`.
|
|
958
|
+
*
|
|
959
|
+
* # Examples
|
|
960
|
+
*
|
|
961
|
+
* Note that this function is polymorphic with respect to the replacement.
|
|
962
|
+
* In typical usage, this can just be a normal string:
|
|
963
|
+
*
|
|
964
|
+
* ```typescript
|
|
965
|
+
* import { RRegex } from "rregex"
|
|
966
|
+
*
|
|
967
|
+
* const re = new RRegex("[^01]+")
|
|
968
|
+
* expect(re.replace("1078910", "").toBe("1010")
|
|
969
|
+
* ```
|
|
970
|
+
*
|
|
971
|
+
* Here's the example using this expansion technique with named capture
|
|
972
|
+
* groups:
|
|
973
|
+
*
|
|
974
|
+
* ```typescript
|
|
975
|
+
* import { RRegex } from "rregex"
|
|
976
|
+
*
|
|
977
|
+
* const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
978
|
+
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
979
|
+
* expect(result).toBe("Bruce Springsteen")
|
|
980
|
+
* ```
|
|
981
|
+
*
|
|
982
|
+
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
983
|
+
* would produce the same result. To write a literal `$` use `$$`.
|
|
984
|
+
*
|
|
985
|
+
* Sometimes the replacement string requires use of curly braces to
|
|
986
|
+
* delineate a capture group replacement and surrounding literal text.
|
|
987
|
+
* For example, if we wanted to join two words together with an
|
|
988
|
+
* underscore:
|
|
989
|
+
*
|
|
990
|
+
* ```typescript
|
|
991
|
+
* import { RRegex } from "rregex"
|
|
992
|
+
*
|
|
993
|
+
* const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
994
|
+
* const result = re.replace("deep fried", "${first}_$second")
|
|
995
|
+
* expect(result).toBe("deep_fried")
|
|
996
|
+
* ```
|
|
997
|
+
*
|
|
998
|
+
* Without the curly braces, the capture group name `first_` would be
|
|
999
|
+
* used, and since it doesn't exist, it would be replaced with the empty
|
|
1000
|
+
* string.
|
|
1001
|
+
*
|
|
1002
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
1003
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1004
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1005
|
+
* @returns {string}
|
|
1006
|
+
*/
|
|
1007
|
+
replace(text: string, rep: string): string;
|
|
1008
|
+
/**
|
|
1009
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
1010
|
+
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
1011
|
+
* are replaced.
|
|
1012
|
+
*
|
|
1013
|
+
* See the documentation for `replace` for details on how to access
|
|
1014
|
+
* capturing group matches in the replacement string.
|
|
1015
|
+
*
|
|
1016
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
1017
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1018
|
+
* @param {number} limit - Max number of replacement
|
|
1019
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1020
|
+
* @returns {string}
|
|
1021
|
+
*/
|
|
1022
|
+
replacen(text: string, limit: number, rep: string): string;
|
|
1023
|
+
/**
|
|
1024
|
+
* Replaces all non-overlapping matches in `text` with the replacement
|
|
1025
|
+
* provided. This is the same as calling `replacen` with `limit` set to
|
|
1026
|
+
* `0`.
|
|
1027
|
+
*
|
|
1028
|
+
* See the documentation for `replace` for details on how to access
|
|
1029
|
+
* capturing group matches in the replacement string.
|
|
1030
|
+
*
|
|
1031
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
1032
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
1033
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1034
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1035
|
+
* @returns {string}
|
|
1036
|
+
*/
|
|
1037
|
+
replaceAll(text: string, rep: string): string;
|
|
1038
|
+
/**
|
|
1039
|
+
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
1040
|
+
* regular expression. Namely, each element of the iterator corresponds to
|
|
1041
|
+
* text that *isn't* matched by the regular expression.
|
|
1042
|
+
*
|
|
1043
|
+
* This method will *not* copy the text given.
|
|
1044
|
+
*
|
|
1045
|
+
* # Example
|
|
1046
|
+
*
|
|
1047
|
+
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
1048
|
+
*
|
|
1049
|
+
* ```typescript
|
|
1050
|
+
* import { RRegex } from "rregex"
|
|
1051
|
+
*
|
|
1052
|
+
* const re = new RRegex(r"[ \\t]+")
|
|
1053
|
+
* const fields = re.split("a b \t c\td e")
|
|
1054
|
+
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
1055
|
+
* ```
|
|
1056
|
+
*
|
|
1057
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
1058
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1059
|
+
* @returns {string[]}
|
|
1060
|
+
*/
|
|
1061
|
+
split(text: string): (string)[];
|
|
1062
|
+
/**
|
|
1063
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
1064
|
+
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
1065
|
+
* substrings.) Namely, each element of the iterator corresponds to text
|
|
1066
|
+
* that *isn't* matched by the regular expression. The remainder of the
|
|
1067
|
+
* string that is not split will be the last element in the iterator.
|
|
1068
|
+
*
|
|
1069
|
+
* This method will *not* copy the text given.
|
|
1070
|
+
*
|
|
1071
|
+
* # Example
|
|
1072
|
+
*
|
|
1073
|
+
* Get the first two words in some text:
|
|
1074
|
+
*
|
|
1075
|
+
* ```typescript
|
|
1076
|
+
* import { RRegex } from "rregex"
|
|
1077
|
+
*
|
|
1078
|
+
* const re = new RRegex(r"\\W+")
|
|
1079
|
+
* const fields = re.splitn("Hey! How are you?", 3)
|
|
1080
|
+
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
1081
|
+
* ```
|
|
1082
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
1083
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1084
|
+
* @param {number} limit - Max number result elements
|
|
1085
|
+
* @returns {string[]}
|
|
1086
|
+
*/
|
|
1087
|
+
splitn(text: string, limit: number): (string)[];
|
|
1088
|
+
/**
|
|
1089
|
+
* Returns the end location of a match in the text given.
|
|
1090
|
+
*
|
|
1091
|
+
* This method may have the same performance characteristics as
|
|
1092
|
+
* `isMatch`, except it provides an end location for a match. In
|
|
1093
|
+
* particular, the location returned *may be shorter* than the proper end
|
|
1094
|
+
* of the leftmost-first match that you would find via `Regex.find`.
|
|
1095
|
+
*
|
|
1096
|
+
* Note that it is not guaranteed that this routine finds the shortest or
|
|
1097
|
+
* "earliest" possible match. Instead, the main idea of this API is that
|
|
1098
|
+
* it returns the offset at the point at which the internal regex engine
|
|
1099
|
+
* has determined that a match has occurred. This may vary depending on
|
|
1100
|
+
* which internal regex engine is used, and thus, the offset itself may
|
|
1101
|
+
* change.
|
|
1102
|
+
*
|
|
1103
|
+
* # Example
|
|
1104
|
+
*
|
|
1105
|
+
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
1106
|
+
* text, but `shortest_match` can give up as soon as it sees the first
|
|
1107
|
+
* `a`.
|
|
1108
|
+
*
|
|
1109
|
+
* ```typescript
|
|
1110
|
+
* import { RRegex } from "rregex"
|
|
1111
|
+
*
|
|
1112
|
+
* const text = "aaaaa"
|
|
1113
|
+
* const = new RRegex("a+").shortest_match(text)
|
|
1114
|
+
* expect(pos).toBe(1)
|
|
1115
|
+
* ```
|
|
1116
|
+
*
|
|
1117
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
1118
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1119
|
+
* @returns {number|undefined}
|
|
1120
|
+
*/
|
|
1121
|
+
shortestMatch(text: string): number | undefined;
|
|
1122
|
+
/**
|
|
1123
|
+
* Returns the same as `shortest_match`, but starts the search at the
|
|
1124
|
+
* given offset.
|
|
1125
|
+
*
|
|
1126
|
+
* The significance of the starting point is that it takes the surrounding
|
|
1127
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
1128
|
+
* when `start == 0`.
|
|
1129
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
1130
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1131
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
1132
|
+
* @returns {number|undefined}
|
|
1133
|
+
*/
|
|
1134
|
+
shortestMatchAt(text: string, start: number): number | undefined;
|
|
1135
|
+
/**
|
|
1136
|
+
* Returns the regular expression into a high level intermediate
|
|
1137
|
+
* representation.
|
|
1138
|
+
* @returns {any}
|
|
1139
|
+
*/
|
|
1140
|
+
syntax(): Hir;
|
|
1141
|
+
/**
|
|
1142
|
+
* Returns a string representing the regular expression
|
|
1143
|
+
* @returns {string}
|
|
1144
|
+
*/
|
|
1145
|
+
toString(): string;
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
1149
|
+
* A regex set corresponds to the union of two or more regular expressions.
|
|
1150
|
+
*
|
|
1151
|
+
* That is, a regex set will match text where at least one of its constituent
|
|
1152
|
+
* regular expressions matches. A regex set as its formulated here provides a
|
|
1153
|
+
* touch more power: it will also report which regular expressions in the set match.
|
|
1154
|
+
* Indeed, this is the key difference between regex sets and a single `Regex`
|
|
1155
|
+
* with many alternates, since only one alternate can match at a time.
|
|
1156
|
+
*
|
|
1157
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
1158
|
+
*/
|
|
1159
|
+
export class RRegexSet {
|
|
1160
|
+
free(): void;
|
|
1161
|
+
/**
|
|
1162
|
+
* Create a new regex set with the given regular expressions.
|
|
1163
|
+
*
|
|
1164
|
+
* This takes an of strings, if any item in the list is not a valid regular
|
|
1165
|
+
* expressions, then an error is returned.
|
|
1166
|
+
*
|
|
1167
|
+
* # Example
|
|
1168
|
+
*
|
|
1169
|
+
* Create a new regex set from an iterator of strings:
|
|
1170
|
+
*
|
|
1171
|
+
* ```typescript
|
|
1172
|
+
* import { RegexSet } from "rregex"
|
|
1173
|
+
*
|
|
1174
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
1175
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
1176
|
+
* ```
|
|
1177
|
+
* @param {Array<any>} list
|
|
1178
|
+
*/
|
|
1179
|
+
constructor(list: Array<any>);
|
|
1180
|
+
/**
|
|
1181
|
+
* Returns true if and only if one of the regexes in this set matches
|
|
1182
|
+
* the text given.
|
|
1183
|
+
*
|
|
1184
|
+
* This method should be preferred if you only need to test whether any
|
|
1185
|
+
* of the regexes in the set should match, but don't care about *which*
|
|
1186
|
+
* regexes matched. This is because the underlying matching engine will
|
|
1187
|
+
* quit immediately after seeing the first match instead of continuing to
|
|
1188
|
+
* find all matches.
|
|
1189
|
+
*
|
|
1190
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
1191
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
1192
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
1193
|
+
* text.
|
|
1194
|
+
*
|
|
1195
|
+
* # Example
|
|
1196
|
+
*
|
|
1197
|
+
* Tests whether a set matches some text:
|
|
1198
|
+
*
|
|
1199
|
+
* ```typescript
|
|
1200
|
+
* import { RegexSet } from "rregex"
|
|
1201
|
+
*
|
|
1202
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
1203
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
1204
|
+
* expect(!set.is_match("☃")).toBe(false)
|
|
1205
|
+
* ```
|
|
1206
|
+
*
|
|
1207
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
1208
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1209
|
+
* @return {boolean}
|
|
1210
|
+
*/
|
|
1211
|
+
isMatch(text: string): boolean;
|
|
1212
|
+
/**
|
|
1213
|
+
* Returns the set of regular expressions that match in the given text.
|
|
1214
|
+
*
|
|
1215
|
+
* The set returned contains the index of each regular expression that
|
|
1216
|
+
* matches in the given text. The index is in correspondence with the
|
|
1217
|
+
* order of regular expressions given to `RegexSet`'s constructor.
|
|
1218
|
+
*
|
|
1219
|
+
* The set can also be used to iterate over the matched indices.
|
|
1220
|
+
*
|
|
1221
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
1222
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
1223
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
1224
|
+
* text.
|
|
1225
|
+
*
|
|
1226
|
+
* # Example
|
|
1227
|
+
*
|
|
1228
|
+
* Tests which regular expressions match the given text:
|
|
1229
|
+
*
|
|
1230
|
+
* ```typescript
|
|
1231
|
+
* import { RegexSet } from "rregex"
|
|
1232
|
+
*
|
|
1233
|
+
* const set = new RegexSet([
|
|
1234
|
+
* "\\w+",
|
|
1235
|
+
* "\\d+",
|
|
1236
|
+
* "\\pL+",
|
|
1237
|
+
* "foo",
|
|
1238
|
+
* "bar",
|
|
1239
|
+
* "barfoo",
|
|
1240
|
+
* "foobar",
|
|
1241
|
+
* ])
|
|
1242
|
+
* const matches = set.matches("foobar")
|
|
1243
|
+
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
1244
|
+
* ```
|
|
1245
|
+
*
|
|
1246
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
1247
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1248
|
+
* @return {number[]}
|
|
1249
|
+
*/
|
|
1250
|
+
matches(text: string): number[];
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
1254
|
+
|
|
1255
|
+
export interface InitOutput {
|
|
1256
|
+
readonly memory: WebAssembly.Memory;
|
|
1257
|
+
readonly __wbg_rregex_free: (a: number) => void;
|
|
1258
|
+
readonly rregex_new: (a: number, b: number, c: number) => void;
|
|
1259
|
+
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
1260
|
+
readonly rregex_isMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1261
|
+
readonly rregex_find: (a: number, b: number, c: number, d: number) => void;
|
|
1262
|
+
readonly rregex_findAt: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
1263
|
+
readonly rregex_findAll: (a: number, b: number, c: number, d: number) => void;
|
|
1264
|
+
readonly rregex_captureNames: (a: number, b: number) => void;
|
|
1265
|
+
readonly rregex_captures: (a: number, b: number, c: number, d: number) => void;
|
|
1266
|
+
readonly rregex_capturesAll: (a: number, b: number, c: number, d: number) => void;
|
|
1267
|
+
readonly rregex_capturesLength: (a: number) => number;
|
|
1268
|
+
readonly rregex_replace: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
1269
|
+
readonly rregex_replacen: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
1270
|
+
readonly rregex_replaceAll: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
1271
|
+
readonly rregex_split: (a: number, b: number, c: number, d: number) => void;
|
|
1272
|
+
readonly rregex_splitn: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
1273
|
+
readonly rregex_shortestMatch: (a: number, b: number, c: number, d: number) => void;
|
|
1274
|
+
readonly rregex_shortestMatchAt: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
1275
|
+
readonly rregex_syntax: (a: number, b: number) => void;
|
|
1276
|
+
readonly rregex_toString: (a: number, b: number) => void;
|
|
1277
|
+
readonly __wbg_rregexset_free: (a: number) => void;
|
|
1278
|
+
readonly rregexset_new: (a: number, b: number) => void;
|
|
1279
|
+
readonly rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
1280
|
+
readonly rregexset_matches: (a: number, b: number, c: number, d: number) => void;
|
|
1281
|
+
readonly escape: (a: number, b: number, c: number) => void;
|
|
1282
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
1283
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
1284
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
1285
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
1286
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
1290
|
+
/**
|
|
1291
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
1292
|
+
* a precompiled `WebAssembly.Module`.
|
|
1293
|
+
*
|
|
1294
|
+
* @param {SyncInitInput} module
|
|
1295
|
+
*
|
|
1296
|
+
* @returns {InitOutput}
|
|
1297
|
+
*/
|
|
1298
|
+
export function initSync(module: SyncInitInput): InitOutput;
|
|
1299
|
+
|
|
1300
|
+
/**
|
|
1301
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
1302
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
1303
|
+
*
|
|
1304
|
+
* @param {InitInput | Promise<InitInput>} module_or_path
|
|
1305
|
+
*
|
|
1306
|
+
* @returns {Promise<InitOutput>}
|
|
1307
|
+
*/
|
|
1308
|
+
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
1309
|
+
|
|
1310
|
+
/** Build metadata */
|
|
1311
|
+
export const metadata: {
|
|
1312
|
+
"name": "rregex",
|
|
1313
|
+
"description": "Rust Regex binding for Javascript",
|
|
1314
|
+
"authors": [
|
|
1315
|
+
"Fede Ramirez <i@2fd.me>"
|
|
1316
|
+
],
|
|
1317
|
+
"homepage": "http://rregex.dev",
|
|
1318
|
+
"repository": "https://github.com/2fd/rregex",
|
|
1319
|
+
"regex": "1.10.4",
|
|
1320
|
+
"regex-syntax": "0.8.3"
|
|
1321
|
+
}
|