rregex 1.8.1 → 1.8.2

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