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.
@@ -0,0 +1,996 @@
1
+
2
+ let imports = {};
3
+ imports['wbg'] = module.exports;
4
+ let wasm;
5
+ const { TextDecoder, TextEncoder } = require(`util`);
6
+
7
+ function addToExternrefTable0(obj) {
8
+ const idx = wasm.__externref_table_alloc();
9
+ wasm.__wbindgen_export_2.set(idx, obj);
10
+ return idx;
11
+ }
12
+
13
+ function handleError(f, args) {
14
+ try {
15
+ return f.apply(this, args);
16
+ } catch (e) {
17
+ const idx = addToExternrefTable0(e);
18
+ wasm.__wbindgen_exn_store(idx);
19
+ }
20
+ }
21
+
22
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
23
+
24
+ cachedTextDecoder.decode();
25
+
26
+ let cachedUint8ArrayMemory0 = null;
27
+
28
+ function getUint8ArrayMemory0() {
29
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
30
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
31
+ }
32
+ return cachedUint8ArrayMemory0;
33
+ }
34
+
35
+ function getStringFromWasm0(ptr, len) {
36
+ ptr = ptr >>> 0;
37
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
38
+ }
39
+
40
+ let WASM_VECTOR_LEN = 0;
41
+
42
+ let cachedTextEncoder = new TextEncoder('utf-8');
43
+
44
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
45
+ ? function (arg, view) {
46
+ return cachedTextEncoder.encodeInto(arg, view);
47
+ }
48
+ : function (arg, view) {
49
+ const buf = cachedTextEncoder.encode(arg);
50
+ view.set(buf);
51
+ return {
52
+ read: arg.length,
53
+ written: buf.length
54
+ };
55
+ });
56
+
57
+ function passStringToWasm0(arg, malloc, realloc) {
58
+
59
+ if (realloc === undefined) {
60
+ const buf = cachedTextEncoder.encode(arg);
61
+ const ptr = malloc(buf.length, 1) >>> 0;
62
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
63
+ WASM_VECTOR_LEN = buf.length;
64
+ return ptr;
65
+ }
66
+
67
+ let len = arg.length;
68
+ let ptr = malloc(len, 1) >>> 0;
69
+
70
+ const mem = getUint8ArrayMemory0();
71
+
72
+ let offset = 0;
73
+
74
+ for (; offset < len; offset++) {
75
+ const code = arg.charCodeAt(offset);
76
+ if (code > 0x7F) break;
77
+ mem[ptr + offset] = code;
78
+ }
79
+
80
+ if (offset !== len) {
81
+ if (offset !== 0) {
82
+ arg = arg.slice(offset);
83
+ }
84
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
85
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
86
+ const ret = encodeString(arg, view);
87
+
88
+ offset += ret.written;
89
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
90
+ }
91
+
92
+ WASM_VECTOR_LEN = offset;
93
+ return ptr;
94
+ }
95
+
96
+ function isLikeNone(x) {
97
+ return x === undefined || x === null;
98
+ }
99
+
100
+ let cachedDataViewMemory0 = null;
101
+
102
+ function getDataViewMemory0() {
103
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
104
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
105
+ }
106
+ return cachedDataViewMemory0;
107
+ }
108
+
109
+ function takeFromExternrefTable0(idx) {
110
+ const value = wasm.__wbindgen_export_2.get(idx);
111
+ wasm.__externref_table_dealloc(idx);
112
+ return value;
113
+ }
114
+
115
+ function getArrayJsValueFromWasm0(ptr, len) {
116
+ ptr = ptr >>> 0;
117
+ const mem = getDataViewMemory0();
118
+ const result = [];
119
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
120
+ result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
121
+ }
122
+ wasm.__externref_drop_slice(ptr, len);
123
+ return result;
124
+ }
125
+ /**
126
+ * Escapes all regular expression meta characters in `text`.
127
+ *
128
+ * The string returned may be safely used as a literal in a regular
129
+ * expression.
130
+ * @param {string} text
131
+ * @returns {string}
132
+ */
133
+ module.exports.escape = function(text) {
134
+ let deferred2_0;
135
+ let deferred2_1;
136
+ try {
137
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
138
+ const len0 = WASM_VECTOR_LEN;
139
+ const ret = wasm.escape(ptr0, len0);
140
+ deferred2_0 = ret[0];
141
+ deferred2_1 = ret[1];
142
+ return getStringFromWasm0(ret[0], ret[1]);
143
+ } finally {
144
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
145
+ }
146
+ };
147
+
148
+ const RRegexFinalization = (typeof FinalizationRegistry === 'undefined')
149
+ ? { register: () => {}, unregister: () => {} }
150
+ : new FinalizationRegistry(ptr => wasm.__wbg_rregex_free(ptr >>> 0, 1));
151
+ /**
152
+ * A compiled regular expression for matching Unicode strings.
153
+ * @see https://docs.rs/regex/latest/regex/
154
+ */
155
+ class RRegex {
156
+
157
+ __destroy_into_raw() {
158
+ const ptr = this.__wbg_ptr;
159
+ this.__wbg_ptr = 0;
160
+ RRegexFinalization.unregister(this);
161
+ return ptr;
162
+ }
163
+
164
+ free() {
165
+ const ptr = this.__destroy_into_raw();
166
+ wasm.__wbg_rregex_free(ptr, 0);
167
+ }
168
+ /**
169
+ * Returns the same as is_match, but starts the search at the given offset.
170
+ * The significance of the starting point is that it takes the surrounding
171
+ * context into consideration. For example, the `\A` anchor can only match
172
+ * when `start == 0`.
173
+ *
174
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
175
+ * @param {string} text - The string against which to match the regular expression
176
+ * @param {number} start - Zero-based index at which to start matching
177
+ * @return {boolean}
178
+ */
179
+ isMatchAt(text, start) {
180
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
181
+ const len0 = WASM_VECTOR_LEN;
182
+ const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
183
+ return ret !== 0;
184
+ }
185
+ /**
186
+ * Replaces all non-overlapping matches in `text` with the replacement
187
+ * provided. This is the same as calling `replacen` with `limit` set to
188
+ * `0`.
189
+ *
190
+ * See the documentation for `replace` for details on how to access
191
+ * capturing group matches in the replacement string.
192
+ *
193
+ * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
194
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
195
+ * @param {string} text - The string against which to match the regular expression
196
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
197
+ * @returns {string}
198
+ */
199
+ replaceAll(text, rep) {
200
+ let deferred3_0;
201
+ let deferred3_1;
202
+ try {
203
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
204
+ const len0 = WASM_VECTOR_LEN;
205
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
206
+ const len1 = WASM_VECTOR_LEN;
207
+ const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
208
+ deferred3_0 = ret[0];
209
+ deferred3_1 = ret[1];
210
+ return getStringFromWasm0(ret[0], ret[1]);
211
+ } finally {
212
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
213
+ }
214
+ }
215
+ /**
216
+ * Returns a list with all the non-overlapping capture groups matched
217
+ * in `text`. This is operationally the same as `findAll`, except it
218
+ * returns information about capturing group matches.
219
+ *
220
+ * # Example
221
+ *
222
+ * We can use this to find all movie titles and their release years in
223
+ * some text, where the movie is formatted like "'Title' (xxxx)":
224
+ *
225
+ * ```typescript
226
+ * const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
227
+ * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
228
+ * for caps of re.captures_iter(text) {
229
+ * console.log(
230
+ * "Movie:", caps.name["title"].value, ","
231
+ * "Released:", caps.name["year"].value
232
+ * );
233
+ * }
234
+ * // Output:
235
+ * // Movie: Citizen Kane, Released: 1941
236
+ * // Movie: The Wizard of Oz, Released: 1939
237
+ * // Movie: M, Released: 1931
238
+ * ```
239
+ *
240
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
241
+ * @param {string} text - The string against which to match the regular expression
242
+ * @returns {Captures[]}
243
+ */
244
+ capturesAll(text) {
245
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
246
+ const len0 = WASM_VECTOR_LEN;
247
+ const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
248
+ if (ret[2]) {
249
+ throw takeFromExternrefTable0(ret[1]);
250
+ }
251
+ return takeFromExternrefTable0(ret[0]);
252
+ }
253
+ /**
254
+ * Returns the number of captures.
255
+ *
256
+ * This includes all named and unnamed groups, including the implicit
257
+ * unnamed group that is always present and corresponds to the entire match.
258
+ *
259
+ * Since the implicit unnamed group is always included in this length, the
260
+ * length returned is guaranteed to be greater than zero.
261
+ *
262
+ * ## Example
263
+ *
264
+ * ```typescript
265
+ * const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
266
+ * expect(re1.capturesLength()).toEqual(4)
267
+ *
268
+ * const re2 = new RRegex("foo")
269
+ * expect(re2.capturesLength()).toEqual(1)
270
+ *
271
+ * const re3 = new RRegex("(foo)")
272
+ * expect(re3.capturesLength()).toEqual(2)
273
+ *
274
+ * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
275
+ * expect(re4.capturesLength()).toEqual(5)
276
+ *
277
+ * const re5 = new RRegex("[a&&b]")
278
+ * expect(re5.capturesLength()).toEqual(1)
279
+ * ```
280
+ *
281
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
282
+ * @returns {number}
283
+ */
284
+ capturesLength() {
285
+ const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
286
+ return ret >>> 0;
287
+ }
288
+ /**
289
+ * Returns a list of the capture names in this regex.
290
+ *
291
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
292
+ */
293
+ captureNames() {
294
+ const ret = wasm.rregex_captureNames(this.__wbg_ptr);
295
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
296
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
297
+ return v1;
298
+ }
299
+ /**
300
+ * Returns the end location of a match in the text given.
301
+ *
302
+ * This method may have the same performance characteristics as
303
+ * `isMatch`, except it provides an end location for a match. In
304
+ * particular, the location returned *may be shorter* than the proper end
305
+ * of the leftmost-first match that you would find via `Regex.find`.
306
+ *
307
+ * Note that it is not guaranteed that this routine finds the shortest or
308
+ * "earliest" possible match. Instead, the main idea of this API is that
309
+ * it returns the offset at the point at which the internal regex engine
310
+ * has determined that a match has occurred. This may vary depending on
311
+ * which internal regex engine is used, and thus, the offset itself may
312
+ * change.
313
+ *
314
+ * # Example
315
+ *
316
+ * Typically, `a+` would match the entire first sequence of `a` in some
317
+ * text, but `shortest_match` can give up as soon as it sees the first
318
+ * `a`.
319
+ *
320
+ * ```typescript
321
+ * const text = "aaaaa"
322
+ * const = new Regex("a+").shortest_match(text)
323
+ * expect(pos).toBe(1)
324
+ * ```
325
+ *
326
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
327
+ * @param {string} text - The string against which to match the regular expression
328
+ * @returns {number|undefined}
329
+ */
330
+ shortestMatch(text) {
331
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
332
+ const len0 = WASM_VECTOR_LEN;
333
+ const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
334
+ return ret === 0x100000001 ? undefined : ret;
335
+ }
336
+ /**
337
+ * Returns the same as `shortest_match`, but starts the search at the
338
+ * given offset.
339
+ *
340
+ * The significance of the starting point is that it takes the surrounding
341
+ * context into consideration. For example, the `\A` anchor can only match
342
+ * when `start == 0`.
343
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
344
+ * @param {string} text - The string against which to match the regular expression
345
+ * @param {number} start - Zero-based index at which to start matching
346
+ * @returns {number|undefined}
347
+ */
348
+ shortestMatchAt(text, start) {
349
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
350
+ const len0 = WASM_VECTOR_LEN;
351
+ const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
352
+ return ret === 0x100000001 ? undefined : ret;
353
+ }
354
+ /**
355
+ * Compiles a regular expression. Once compiled, it can be used repeatedly
356
+ * to search, split or replace text in a string.
357
+ *
358
+ * If an invalid expression is given, then an error is returned.
359
+ * @param {string} re
360
+ */
361
+ constructor(re) {
362
+ const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
363
+ const len0 = WASM_VECTOR_LEN;
364
+ const ret = wasm.rregex_new(ptr0, len0);
365
+ if (ret[2]) {
366
+ throw takeFromExternrefTable0(ret[1]);
367
+ }
368
+ this.__wbg_ptr = ret[0] >>> 0;
369
+ RRegexFinalization.register(this, this.__wbg_ptr, this);
370
+ return this;
371
+ }
372
+ /**
373
+ * Returns the start and end byte range of the leftmost-first match in
374
+ * `text`. If no match exists, then `undefined` is returned.
375
+ *
376
+ * Note that this should only be used if you want to discover the position
377
+ * of the match. Testing the existence of a match is faster if you use
378
+ * `isMatch`.
379
+ *
380
+ * # Example
381
+ *
382
+ * Find the start and end location of the first word with exactly 13
383
+ * Unicode word characters:
384
+ *
385
+ * ```typescript
386
+ * const text = "I categorically deny having triskaidekaphobia."
387
+ * const m = new Regex("\\b\\w{13}\\b").find(text)
388
+ * expect(m.start).toBe(2)
389
+ * expect(m.end).toBe(15)
390
+ * ```
391
+ *
392
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
393
+ * @param {string} text - The string against which to match the regular expression
394
+ * @return {Match}
395
+ */
396
+ find(text) {
397
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
398
+ const len0 = WASM_VECTOR_LEN;
399
+ const ret = wasm.rregex_find(this.__wbg_ptr, ptr0, len0);
400
+ if (ret[2]) {
401
+ throw takeFromExternrefTable0(ret[1]);
402
+ }
403
+ return takeFromExternrefTable0(ret[0]);
404
+ }
405
+ /**
406
+ * Returns an iterator of substrings of `text` delimited by a match of the
407
+ * regular expression. Namely, each element of the iterator corresponds to
408
+ * text that *isn't* matched by the regular expression.
409
+ *
410
+ * This method will *not* copy the text given.
411
+ *
412
+ * # Example
413
+ *
414
+ * To split a string delimited by arbitrary amounts of spaces or tabs:
415
+ *
416
+ * ```typescript
417
+ * const re = new Regex(r"[ \\t]+")
418
+ * const fields = re.split("a b \t c\td e")
419
+ * expect(fields).toEqual(["a", "b", "c", "d", "e"])
420
+ * ```
421
+ *
422
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
423
+ * @param {string} text - The string against which to match the regular expression
424
+ * @returns {string[]}
425
+ */
426
+ split(text) {
427
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
428
+ const len0 = WASM_VECTOR_LEN;
429
+ const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
430
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
431
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
432
+ return v2;
433
+ }
434
+ /**
435
+ * Returns an iterator of at most `limit` substrings of `text` delimited
436
+ * by a match of the regular expression. (A `limit` of `0` will return no
437
+ * substrings.) Namely, each element of the iterator corresponds to text
438
+ * that *isn't* matched by the regular expression. The remainder of the
439
+ * string that is not split will be the last element in the iterator.
440
+ *
441
+ * This method will *not* copy the text given.
442
+ *
443
+ * # Example
444
+ *
445
+ * Get the first two words in some text:
446
+ *
447
+ * ```typescript
448
+ * const re = new Regex(r"\\W+")
449
+ * const fields = re.splitn("Hey! How are you?", 3)
450
+ * expect(fields).toEqual(["Hey", "How", "are you?"])
451
+ * ```
452
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
453
+ * @param {string} text - The string against which to match the regular expression
454
+ * @param {number} limit - Max number result elements
455
+ * @returns {string[]}
456
+ */
457
+ splitn(text, limit) {
458
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
459
+ const len0 = WASM_VECTOR_LEN;
460
+ const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
461
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
462
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
463
+ return v2;
464
+ }
465
+ /**
466
+ * Returns the regular expression into a high level intermediate
467
+ * representation.
468
+ * @returns {any}
469
+ */
470
+ syntax() {
471
+ const ret = wasm.rregex_syntax(this.__wbg_ptr);
472
+ if (ret[2]) {
473
+ throw takeFromExternrefTable0(ret[1]);
474
+ }
475
+ return takeFromExternrefTable0(ret[0]);
476
+ }
477
+ /**
478
+ * Returns the same as find, but starts the search at the given
479
+ * offset.
480
+ *
481
+ * The significance of the starting point is that it takes the surrounding
482
+ * context into consideration. For example, the `\A` anchor can only
483
+ * match when `start == 0`.
484
+ *
485
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
486
+ * @param {string} text - The string against which to match the regular expression
487
+ * @param {number} start - Zero-based index at which to start matching
488
+ * @returns {Match}
489
+ */
490
+ findAt(text, start) {
491
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
492
+ const len0 = WASM_VECTOR_LEN;
493
+ const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
494
+ if (ret[2]) {
495
+ throw takeFromExternrefTable0(ret[1]);
496
+ }
497
+ return takeFromExternrefTable0(ret[0]);
498
+ }
499
+ /**
500
+ * Replaces the leftmost-first match with the replacement provided.
501
+ * The replacement can be a regular string (where `$N` and `$name` are
502
+ * expanded to match capture groups) or a function that takes the matches'
503
+ * `Captures` and returns the replaced string.
504
+ *
505
+ * If no match is found, then a copy of the string is returned unchanged.
506
+ *
507
+ * # Replacement string syntax
508
+ *
509
+ * All instances of `$name` in the replacement text is replaced with the
510
+ * corresponding capture group `name`.
511
+ *
512
+ * `name` may be an integer corresponding to the index of the
513
+ * capture group (counted by order of opening parenthesis where `0` is the
514
+ * entire match) or it can be a name (consisting of letters, digits or
515
+ * underscores) corresponding to a named capture group.
516
+ *
517
+ * If `name` isn't a valid capture group (whether the name doesn't exist
518
+ * or isn't a valid index), then it is replaced with the empty string.
519
+ *
520
+ * The longest possible name is used. e.g., `$1a` looks up the capture
521
+ * group named `1a` and not the capture group at index `1`. To exert more
522
+ * precise control over the name, use braces, e.g., `${1}a`.
523
+ *
524
+ * To write a literal `$` use `$$`.
525
+ *
526
+ * # Examples
527
+ *
528
+ * Note that this function is polymorphic with respect to the replacement.
529
+ * In typical usage, this can just be a normal string:
530
+ *
531
+ * ```typescript
532
+ * const re = new Regex("[^01]+")
533
+ * expect(re.replace("1078910", "").toBe("1010")
534
+ * ```
535
+ *
536
+ * Here's the example using this expansion technique with named capture
537
+ * groups:
538
+ *
539
+ * ```typescript
540
+ * const re = new Regex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
541
+ * const result = re.replace("Springsteen, Bruce", "$first $last")
542
+ * expect(result).toBe("Bruce Springsteen")
543
+ * ```
544
+ *
545
+ * Note that using `$2` instead of `$first` or `$1` instead of `$last`
546
+ * would produce the same result. To write a literal `$` use `$$`.
547
+ *
548
+ * Sometimes the replacement string requires use of curly braces to
549
+ * delineate a capture group replacement and surrounding literal text.
550
+ * For example, if we wanted to join two words together with an
551
+ * underscore:
552
+ *
553
+ * ```typescript
554
+ * const re = new Regex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
555
+ * const result = re.replace("deep fried", "${first}_$second")
556
+ * expect(result).toBe("deep_fried")
557
+ * ```
558
+ *
559
+ * Without the curly braces, the capture group name `first_` would be
560
+ * used, and since it doesn't exist, it would be replaced with the empty
561
+ * string.
562
+ *
563
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
564
+ * @param {string} text - The string against which to match the regular expression
565
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
566
+ * @returns {string}
567
+ */
568
+ replace(text, rep) {
569
+ let deferred3_0;
570
+ let deferred3_1;
571
+ try {
572
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
573
+ const len0 = WASM_VECTOR_LEN;
574
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
575
+ const len1 = WASM_VECTOR_LEN;
576
+ const ret = wasm.rregex_replace(this.__wbg_ptr, ptr0, len0, ptr1, len1);
577
+ deferred3_0 = ret[0];
578
+ deferred3_1 = ret[1];
579
+ return getStringFromWasm0(ret[0], ret[1]);
580
+ } finally {
581
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
582
+ }
583
+ }
584
+ /**
585
+ * Returns the capture groups corresponding to the leftmost-first
586
+ * match in `text`. Capture group `0` always corresponds to the entire
587
+ * match. If no match is found, then `undefined` is returned.
588
+ *
589
+ * You should only use `captures` if you need access to the location of
590
+ * capturing group matches. Otherwise, `find` is faster for discovering
591
+ * the location of the overall match.
592
+ *
593
+ * # Examples
594
+ *
595
+ * Say you have some text with movie names and their release years,
596
+ * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
597
+ * looking like that, while also extracting the movie name and its release
598
+ * year separately.
599
+ *
600
+ * ```typescript
601
+ * const re = new Regex("'([^']+)'\\s+\\((\\d{4})\)")
602
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
603
+ * const caps = re.captures(text)
604
+ * expect(caps.get[1].value).toBe("Citizen Kane")
605
+ * expect(caps.get[2].value).toBe("1941")
606
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
607
+ * ```
608
+ *
609
+ * Note that the full match is at capture group `0`. Each subsequent
610
+ * capture group is indexed by the order of its opening `(`.
611
+ *
612
+ * We can make this example a bit clearer by using *named* capture groups:
613
+ *
614
+ * ```typescript
615
+ * const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
616
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
617
+ * const caps = re.captures(text)
618
+ * expect(caps.name["title"].value).toBe("Citizen Kane")
619
+ * expect(caps.name["year"].value).toBe("1941")
620
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
621
+ * ```
622
+ *
623
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
624
+ * @param {string} text - The string against which to match the regular expression
625
+ * @returns {Captures|undefined}
626
+ */
627
+ captures(text) {
628
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
629
+ const len0 = WASM_VECTOR_LEN;
630
+ const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
631
+ if (ret[2]) {
632
+ throw takeFromExternrefTable0(ret[1]);
633
+ }
634
+ return takeFromExternrefTable0(ret[0]);
635
+ }
636
+ /**
637
+ * Returns an array for each successive non-overlapping match in `text``,
638
+ * returning the start and end byte indices with respect to `text`.
639
+ *
640
+ * # Example
641
+ *
642
+ * Find the start and end location of every word with exactly 13 Unicode
643
+ * word characters:
644
+ *
645
+ * ```typescript
646
+ * const text = "Retroactively relinquishing remunerations is reprehensible."
647
+ * const matches = new Regex("\\b\\w{13}\\b").findAll(text)
648
+ * ```
649
+ *
650
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
651
+ * @param {string} text - The string against which to match the regular expression
652
+ * @returns {Match}
653
+ */
654
+ findAll(text) {
655
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
656
+ const len0 = WASM_VECTOR_LEN;
657
+ const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
658
+ if (ret[2]) {
659
+ throw takeFromExternrefTable0(ret[1]);
660
+ }
661
+ return takeFromExternrefTable0(ret[0]);
662
+ }
663
+ /**
664
+ * Returns true if and only if there is a match for the regex in the
665
+ * string given.
666
+ *
667
+ * It is recommended to use this method if all you need to do is test
668
+ * a match, since the underlying matching engine may be able to do less
669
+ * work.
670
+ *
671
+ * # Example
672
+ *
673
+ * Test if some text contains at least one word with exactly 13
674
+ * Unicode word characters:
675
+ *
676
+ * ```typescript
677
+ * const text = "I categorically deny having triskaidekaphobia."
678
+ * expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
679
+ * ```
680
+ *
681
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
682
+ * @param {string} text - The string against which to match the regular expression
683
+ * @return {boolean}
684
+ */
685
+ isMatch(text) {
686
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
687
+ const len0 = WASM_VECTOR_LEN;
688
+ const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
689
+ return ret !== 0;
690
+ }
691
+ /**
692
+ * Replaces at most `limit` non-overlapping matches in `text` with the
693
+ * replacement provided. If `limit` is 0, then all non-overlapping matches
694
+ * are replaced.
695
+ *
696
+ * See the documentation for `replace` for details on how to access
697
+ * capturing group matches in the replacement string.
698
+ *
699
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
700
+ * @param {string} text - The string against which to match the regular expression
701
+ * @param {number} limit - Max number of replacement
702
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
703
+ * @returns {string}
704
+ */
705
+ replacen(text, limit, rep) {
706
+ let deferred3_0;
707
+ let deferred3_1;
708
+ try {
709
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
710
+ const len0 = WASM_VECTOR_LEN;
711
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
712
+ const len1 = WASM_VECTOR_LEN;
713
+ const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
714
+ deferred3_0 = ret[0];
715
+ deferred3_1 = ret[1];
716
+ return getStringFromWasm0(ret[0], ret[1]);
717
+ } finally {
718
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
719
+ }
720
+ }
721
+ /**
722
+ * Returns a string representing the regular expression
723
+ * @returns {string}
724
+ */
725
+ toString() {
726
+ let deferred1_0;
727
+ let deferred1_1;
728
+ try {
729
+ const ret = wasm.rregex_toString(this.__wbg_ptr);
730
+ deferred1_0 = ret[0];
731
+ deferred1_1 = ret[1];
732
+ return getStringFromWasm0(ret[0], ret[1]);
733
+ } finally {
734
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
735
+ }
736
+ }
737
+ }
738
+ module.exports.RRegex = RRegex;
739
+
740
+ const RRegexSetFinalization = (typeof FinalizationRegistry === 'undefined')
741
+ ? { register: () => {}, unregister: () => {} }
742
+ : new FinalizationRegistry(ptr => wasm.__wbg_rregexset_free(ptr >>> 0, 1));
743
+ /**
744
+ * Match multiple (possibly overlapping) regular expressions in a single scan.
745
+ * A regex set corresponds to the union of two or more regular expressions.
746
+ *
747
+ * That is, a regex set will match text where at least one of its constituent
748
+ * regular expressions matches. A regex set as its formulated here provides a
749
+ * touch more power: it will also report which regular expressions in the set match.
750
+ * Indeed, this is the key difference between regex sets and a single `Regex`
751
+ * with many alternates, since only one alternate can match at a time.
752
+ *
753
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
754
+ */
755
+ class RRegexSet {
756
+
757
+ __destroy_into_raw() {
758
+ const ptr = this.__wbg_ptr;
759
+ this.__wbg_ptr = 0;
760
+ RRegexSetFinalization.unregister(this);
761
+ return ptr;
762
+ }
763
+
764
+ free() {
765
+ const ptr = this.__destroy_into_raw();
766
+ wasm.__wbg_rregexset_free(ptr, 0);
767
+ }
768
+ /**
769
+ * Create a new regex set with the given regular expressions.
770
+ *
771
+ * This takes an of strings, if any item in the list is not a valid regular
772
+ * expressions, then an error is returned.
773
+ *
774
+ * # Example
775
+ *
776
+ * Create a new regex set from an iterator of strings:
777
+ *
778
+ * ```typescript
779
+ * const set = new RegexSet(["\\w+", "\\d+"])
780
+ * expect(set.is_match("foo")).toBe(true)
781
+ * ```
782
+ * @param {Array<any>} list
783
+ */
784
+ constructor(list) {
785
+ const ret = wasm.rregexset_new(list);
786
+ if (ret[2]) {
787
+ throw takeFromExternrefTable0(ret[1]);
788
+ }
789
+ this.__wbg_ptr = ret[0] >>> 0;
790
+ RRegexSetFinalization.register(this, this.__wbg_ptr, this);
791
+ return this;
792
+ }
793
+ /**
794
+ * Returns the set of regular expressions that match in the given text.
795
+ *
796
+ * The set returned contains the index of each regular expression that
797
+ * matches in the given text. The index is in correspondence with the
798
+ * order of regular expressions given to `RegexSet`'s constructor.
799
+ *
800
+ * The set can also be used to iterate over the matched indices.
801
+ *
802
+ * Note that as with searches using `Regex`, the expression is unanchored
803
+ * by default. That is, if the regex does not start with `^` or `\A`, or
804
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
805
+ * text.
806
+ *
807
+ * # Example
808
+ *
809
+ * Tests which regular expressions match the given text:
810
+ *
811
+ * ```typescript
812
+ * const set = new RegexSet([
813
+ * "\\w+",
814
+ * "\\d+",
815
+ * "\\pL+",
816
+ * "foo",
817
+ * "bar",
818
+ * "barfoo",
819
+ * "foobar",
820
+ * ])
821
+ * const matches = set.matches("foobar")
822
+ * expect(matches).toBe([0, 2, 3, 4, 6])
823
+ * ```
824
+ *
825
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
826
+ * @param {string} text - The string against which to match the regular expression
827
+ * @return {number[]}
828
+ */
829
+ matches(text) {
830
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
831
+ const len0 = WASM_VECTOR_LEN;
832
+ const ret = wasm.rregexset_matches(this.__wbg_ptr, ptr0, len0);
833
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
834
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
835
+ return v2;
836
+ }
837
+ /**
838
+ * Returns true if and only if one of the regexes in this set matches
839
+ * the text given.
840
+ *
841
+ * This method should be preferred if you only need to test whether any
842
+ * of the regexes in the set should match, but don't care about *which*
843
+ * regexes matched. This is because the underlying matching engine will
844
+ * quit immediately after seeing the first match instead of continuing to
845
+ * find all matches.
846
+ *
847
+ * Note that as with searches using `Regex`, the expression is unanchored
848
+ * by default. That is, if the regex does not start with `^` or `\A`, or
849
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
850
+ * text.
851
+ *
852
+ * # Example
853
+ *
854
+ * Tests whether a set matches some text:
855
+ *
856
+ * ```typescript
857
+ * const set = new RegexSet(["\\w+", "\\d+"])
858
+ * expect(set.is_match("foo")).toBe(true)
859
+ * expect(!set.is_match("☃")).toBe(false)
860
+ * ```
861
+ *
862
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
863
+ * @param {string} text - The string against which to match the regular expression
864
+ * @return {boolean}
865
+ */
866
+ isMatch(text) {
867
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
868
+ const len0 = WASM_VECTOR_LEN;
869
+ const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
870
+ return ret !== 0;
871
+ }
872
+ }
873
+ module.exports.RRegexSet = RRegexSet;
874
+
875
+ module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
876
+ const ret = arg0.buffer;
877
+ return ret;
878
+ };
879
+
880
+ module.exports.__wbg_fromCodePoint_f37c25c172f2e8b5 = function() { return handleError(function (arg0) {
881
+ const ret = String.fromCodePoint(arg0 >>> 0);
882
+ return ret;
883
+ }, arguments) };
884
+
885
+ module.exports.__wbg_from_2a5d3e218e67aa85 = function(arg0) {
886
+ const ret = Array.from(arg0);
887
+ return ret;
888
+ };
889
+
890
+ module.exports.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
891
+ const ret = arg0[arg1 >>> 0];
892
+ return ret;
893
+ };
894
+
895
+ module.exports.__wbg_length_e2d2a49132c1b256 = function(arg0) {
896
+ const ret = arg0.length;
897
+ return ret;
898
+ };
899
+
900
+ module.exports.__wbg_new_405e22f390576ce2 = function() {
901
+ const ret = new Object();
902
+ return ret;
903
+ };
904
+
905
+ module.exports.__wbg_new_78feb108b6472713 = function() {
906
+ const ret = new Array();
907
+ return ret;
908
+ };
909
+
910
+ module.exports.__wbg_new_a12002a7f91c75be = function(arg0) {
911
+ const ret = new Uint8Array(arg0);
912
+ return ret;
913
+ };
914
+
915
+ module.exports.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
916
+ const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
917
+ return ret;
918
+ };
919
+
920
+ module.exports.__wbg_push_737cfc8c1432c2c6 = function(arg0, arg1) {
921
+ const ret = arg0.push(arg1);
922
+ return ret;
923
+ };
924
+
925
+ module.exports.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
926
+ arg0[arg1 >>> 0] = arg2;
927
+ };
928
+
929
+ module.exports.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
930
+ arg0[arg1] = arg2;
931
+ };
932
+
933
+ module.exports.__wbg_set_bb8cecf6a62b9f46 = function() { return handleError(function (arg0, arg1, arg2) {
934
+ const ret = Reflect.set(arg0, arg1, arg2);
935
+ return ret;
936
+ }, arguments) };
937
+
938
+ module.exports.__wbindgen_bigint_from_u64 = function(arg0) {
939
+ const ret = BigInt.asUintN(64, arg0);
940
+ return ret;
941
+ };
942
+
943
+ module.exports.__wbindgen_error_new = function(arg0, arg1) {
944
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
945
+ return ret;
946
+ };
947
+
948
+ module.exports.__wbindgen_init_externref_table = function() {
949
+ const table = wasm.__wbindgen_export_2;
950
+ const offset = table.grow(4);
951
+ table.set(0, undefined);
952
+ table.set(offset + 0, undefined);
953
+ table.set(offset + 1, null);
954
+ table.set(offset + 2, true);
955
+ table.set(offset + 3, false);
956
+ ;
957
+ };
958
+
959
+ module.exports.__wbindgen_memory = function() {
960
+ const ret = wasm.memory;
961
+ return ret;
962
+ };
963
+
964
+ module.exports.__wbindgen_number_new = function(arg0) {
965
+ const ret = arg0;
966
+ return ret;
967
+ };
968
+
969
+ module.exports.__wbindgen_string_get = function(arg0, arg1) {
970
+ const obj = arg1;
971
+ const ret = typeof(obj) === 'string' ? obj : undefined;
972
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
973
+ var len1 = WASM_VECTOR_LEN;
974
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
975
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
976
+ };
977
+
978
+ module.exports.__wbindgen_string_new = function(arg0, arg1) {
979
+ const ret = getStringFromWasm0(arg0, arg1);
980
+ return ret;
981
+ };
982
+
983
+ module.exports.__wbindgen_throw = function(arg0, arg1) {
984
+ throw new Error(getStringFromWasm0(arg0, arg1));
985
+ };
986
+
987
+ const path = require('path').join(__dirname, 'rregex.wasm');
988
+ const bytes = require('fs').readFileSync(path);
989
+
990
+ const wasmModule = new WebAssembly.Module(bytes);
991
+ const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
992
+ wasm = wasmInstance.exports;
993
+ module.exports.__wasm = wasm;
994
+
995
+ wasm.__wbindgen_start();
996
+