rregex 1.11.0 → 1.12.0

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/esm.mjs CHANGED
@@ -191,69 +191,214 @@ export class RRegex {
191
191
  wasm.__wbg_rregex_free(ptr, 0);
192
192
  }
193
193
  /**
194
- * Compiles a regular expression. Once compiled, it can be used repeatedly
195
- * to search, split or replace text in a string.
194
+ * Returns the same as is_match, but starts the search at the given offset.
195
+ * The significance of the starting point is that it takes the surrounding
196
+ * context into consideration. For example, the `\A` anchor can only match
197
+ * when `start == 0`.
196
198
  *
197
- * If an invalid expression is given, then an error is returned.
198
- * @param {string} re
199
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
200
+ * @param {string} text - The string against which to match the regular expression
201
+ * @param {number} start - Zero-based index at which to start matching
202
+ * @return {boolean}
199
203
  */
200
- constructor(re) {
201
- const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
204
+ isMatchAt(text, start) {
205
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
202
206
  const len0 = WASM_VECTOR_LEN;
203
- const ret = wasm.rregex_new(ptr0, len0);
207
+ const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
208
+ return ret !== 0;
209
+ }
210
+ /**
211
+ * Replaces all non-overlapping matches in `text` with the replacement
212
+ * provided. This is the same as calling `replacen` with `limit` set to
213
+ * `0`.
214
+ *
215
+ * See the documentation for `replace` for details on how to access
216
+ * capturing group matches in the replacement string.
217
+ *
218
+ * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
219
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
220
+ * @param {string} text - The string against which to match the regular expression
221
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
222
+ * @returns {string}
223
+ */
224
+ replaceAll(text, rep) {
225
+ let deferred3_0;
226
+ let deferred3_1;
227
+ try {
228
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
229
+ const len0 = WASM_VECTOR_LEN;
230
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
231
+ const len1 = WASM_VECTOR_LEN;
232
+ const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
233
+ deferred3_0 = ret[0];
234
+ deferred3_1 = ret[1];
235
+ return getStringFromWasm0(ret[0], ret[1]);
236
+ } finally {
237
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
238
+ }
239
+ }
240
+ /**
241
+ * Returns a list with all the non-overlapping capture groups matched
242
+ * in `text`. This is operationally the same as `findAll`, except it
243
+ * returns information about capturing group matches.
244
+ *
245
+ * # Example
246
+ *
247
+ * We can use this to find all movie titles and their release years in
248
+ * some text, where the movie is formatted like "'Title' (xxxx)":
249
+ *
250
+ * ```typescript
251
+ * import { RRegex } from "rregex"
252
+ *
253
+ * const re = new RRegex("'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)")
254
+ * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
255
+ * for caps of re.captures_iter(text) {
256
+ * console.log(
257
+ * "Movie:", caps.name["title"].value, ","
258
+ * "Released:", caps.name["year"].value
259
+ * );
260
+ * }
261
+ * // Output:
262
+ * // Movie: Citizen Kane, Released: 1941
263
+ * // Movie: The Wizard of Oz, Released: 1939
264
+ * // Movie: M, Released: 1931
265
+ * ```
266
+ *
267
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
268
+ * @param {string} text - The string against which to match the regular expression
269
+ * @returns {Captures[]}
270
+ */
271
+ capturesAll(text) {
272
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
273
+ const len0 = WASM_VECTOR_LEN;
274
+ const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
204
275
  if (ret[2]) {
205
276
  throw takeFromExternrefTable0(ret[1]);
206
277
  }
207
- this.__wbg_ptr = ret[0] >>> 0;
208
- RRegexFinalization.register(this, this.__wbg_ptr, this);
209
- return this;
278
+ return takeFromExternrefTable0(ret[0]);
210
279
  }
211
280
  /**
212
- * Returns true if and only if there is a match for the regex in the
213
- * string given.
281
+ * Returns the number of captures.
214
282
  *
215
- * It is recommended to use this method if all you need to do is test
216
- * a match, since the underlying matching engine may be able to do less
217
- * work.
283
+ * This includes all named and unnamed groups, including the implicit
284
+ * unnamed group that is always present and corresponds to the entire match.
285
+ *
286
+ * Since the implicit unnamed group is always included in this length, the
287
+ * length returned is guaranteed to be greater than zero.
288
+ *
289
+ * ## Example
290
+ *
291
+ * ```typescript
292
+ * import { RRegex } from "rregex"
293
+ *
294
+ * const re1 = new RRegex("(?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2})")
295
+ * expect(re1.capturesLength()).toEqual(4)
296
+ *
297
+ * const re2 = new RRegex("foo")
298
+ * expect(re2.capturesLength()).toEqual(1)
299
+ *
300
+ * const re3 = new RRegex("(foo)")
301
+ * expect(re3.capturesLength()).toEqual(2)
302
+ *
303
+ * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
304
+ * expect(re4.capturesLength()).toEqual(5)
305
+ *
306
+ * const re5 = new RRegex("[a&&b]")
307
+ * expect(re5.capturesLength()).toEqual(1)
308
+ * ```
309
+ *
310
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
311
+ * @returns {number}
312
+ */
313
+ capturesLength() {
314
+ const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
315
+ return ret >>> 0;
316
+ }
317
+ /**
318
+ * Returns a list of the capture names in this regex.
319
+ *
320
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
321
+ */
322
+ captureNames() {
323
+ const ret = wasm.rregex_captureNames(this.__wbg_ptr);
324
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
325
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
326
+ return v1;
327
+ }
328
+ /**
329
+ * Returns the end location of a match in the text given.
330
+ *
331
+ * This method may have the same performance characteristics as
332
+ * `isMatch`, except it provides an end location for a match. In
333
+ * particular, the location returned *may be shorter* than the proper end
334
+ * of the leftmost-first match that you would find via `Regex.find`.
335
+ *
336
+ * Note that it is not guaranteed that this routine finds the shortest or
337
+ * "earliest" possible match. Instead, the main idea of this API is that
338
+ * it returns the offset at the point at which the internal regex engine
339
+ * has determined that a match has occurred. This may vary depending on
340
+ * which internal regex engine is used, and thus, the offset itself may
341
+ * change.
218
342
  *
219
343
  * # Example
220
344
  *
221
- * Test if some text contains at least one word with exactly 13
222
- * Unicode word characters:
345
+ * Typically, `a+` would match the entire first sequence of `a` in some
346
+ * text, but `shortest_match` can give up as soon as it sees the first
347
+ * `a`.
223
348
  *
224
349
  * ```typescript
225
350
  * import { RRegex } from "rregex"
226
351
  *
227
- * const text = "I categorically deny having triskaidekaphobia."
228
- * expect(new RRegex("\b\w{13}\b").is_match(text)).toBe(true)
352
+ * const text = "aaaaa"
353
+ * const = new RRegex("a+").shortest_match(text)
354
+ * expect(pos).toBe(1)
229
355
  * ```
230
356
  *
231
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
357
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
232
358
  * @param {string} text - The string against which to match the regular expression
233
- * @return {boolean}
359
+ * @returns {number|undefined}
234
360
  */
235
- isMatch(text) {
361
+ shortestMatch(text) {
236
362
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
237
363
  const len0 = WASM_VECTOR_LEN;
238
- const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
239
- return ret !== 0;
364
+ const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
365
+ return ret === 0x100000001 ? undefined : ret;
240
366
  }
241
367
  /**
242
- * Returns the same as is_match, but starts the search at the given offset.
368
+ * Returns the same as `shortest_match`, but starts the search at the
369
+ * given offset.
370
+ *
243
371
  * The significance of the starting point is that it takes the surrounding
244
372
  * context into consideration. For example, the `\A` anchor can only match
245
373
  * when `start == 0`.
246
- *
247
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
374
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
248
375
  * @param {string} text - The string against which to match the regular expression
249
376
  * @param {number} start - Zero-based index at which to start matching
250
- * @return {boolean}
377
+ * @returns {number|undefined}
251
378
  */
252
- isMatchAt(text, start) {
379
+ shortestMatchAt(text, start) {
253
380
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
254
381
  const len0 = WASM_VECTOR_LEN;
255
- const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
256
- return ret !== 0;
382
+ const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
383
+ return ret === 0x100000001 ? undefined : ret;
384
+ }
385
+ /**
386
+ * Compiles a regular expression. Once compiled, it can be used repeatedly
387
+ * to search, split or replace text in a string.
388
+ *
389
+ * If an invalid expression is given, then an error is returned.
390
+ * @param {string} re
391
+ */
392
+ constructor(re) {
393
+ const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
394
+ const len0 = WASM_VECTOR_LEN;
395
+ const ret = wasm.rregex_new(ptr0, len0);
396
+ if (ret[2]) {
397
+ throw takeFromExternrefTable0(ret[1]);
398
+ }
399
+ this.__wbg_ptr = ret[0] >>> 0;
400
+ RRegexFinalization.register(this, this.__wbg_ptr, this);
401
+ return this;
257
402
  }
258
403
  /**
259
404
  * Returns the start and end byte range of the leftmost-first match in
@@ -291,200 +436,103 @@ export class RRegex {
291
436
  return takeFromExternrefTable0(ret[0]);
292
437
  }
293
438
  /**
294
- * Returns the same as find, but starts the search at the given
295
- * offset.
296
- *
297
- * The significance of the starting point is that it takes the surrounding
298
- * context into consideration. For example, the `\A` anchor can only
299
- * match when `start == 0`.
439
+ * Returns an iterator of substrings of `text` delimited by a match of the
440
+ * regular expression. Namely, each element of the iterator corresponds to
441
+ * text that *isn't* matched by the regular expression.
300
442
  *
301
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
302
- * @param {string} text - The string against which to match the regular expression
303
- * @param {number} start - Zero-based index at which to start matching
304
- * @returns {Match}
305
- */
306
- findAt(text, start) {
307
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
308
- const len0 = WASM_VECTOR_LEN;
309
- const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
310
- if (ret[2]) {
311
- throw takeFromExternrefTable0(ret[1]);
312
- }
313
- return takeFromExternrefTable0(ret[0]);
314
- }
315
- /**
316
- * Returns an array for each successive non-overlapping match in `text``,
317
- * returning the start and end byte indices with respect to `text`.
443
+ * This method will *not* copy the text given.
318
444
  *
319
445
  * # Example
320
446
  *
321
- * Find the start and end location of every word with exactly 13 Unicode
322
- * word characters:
447
+ * To split a string delimited by arbitrary amounts of spaces or tabs:
323
448
  *
324
449
  * ```typescript
325
450
  * import { RRegex } from "rregex"
326
451
  *
327
- * const text = "Retroactively relinquishing remunerations is reprehensible."
328
- * const matches = new RRegex("\b\w{13}\b").findAll(text)
452
+ * const re = new RRegex(r"[ \t]+")
453
+ * const fields = re.split("a b c d e")
454
+ * expect(fields).toEqual(["a", "b", "c", "d", "e"])
329
455
  * ```
330
456
  *
331
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
457
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
332
458
  * @param {string} text - The string against which to match the regular expression
333
- * @returns {Match}
459
+ * @returns {string[]}
334
460
  */
335
- findAll(text) {
461
+ split(text) {
336
462
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
337
463
  const len0 = WASM_VECTOR_LEN;
338
- const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
339
- if (ret[2]) {
340
- throw takeFromExternrefTable0(ret[1]);
341
- }
342
- return takeFromExternrefTable0(ret[0]);
343
- }
344
- /**
345
- * Returns a list of the capture names in this regex.
346
- *
347
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
348
- */
349
- captureNames() {
350
- const ret = wasm.rregex_captureNames(this.__wbg_ptr);
351
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
464
+ const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
465
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
352
466
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
353
- return v1;
467
+ return v2;
354
468
  }
355
469
  /**
356
- * Returns the capture groups corresponding to the leftmost-first
357
- * match in `text`. Capture group `0` always corresponds to the entire
358
- * match. If no match is found, then `undefined` is returned.
359
- *
360
- * You should only use `captures` if you need access to the location of
361
- * capturing group matches. Otherwise, `find` is faster for discovering
362
- * the location of the overall match.
363
- *
364
- * # Examples
365
- *
366
- * Say you have some text with movie names and their release years,
367
- * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
368
- * looking like that, while also extracting the movie name and its release
369
- * year separately.
370
- *
371
- * ```typescript
372
- * import { RRegex } from "rregex"
470
+ * Returns an iterator of at most `limit` substrings of `text` delimited
471
+ * by a match of the regular expression. (A `limit` of `0` will return no
472
+ * substrings.) Namely, each element of the iterator corresponds to text
473
+ * that *isn't* matched by the regular expression. The remainder of the
474
+ * string that is not split will be the last element in the iterator.
373
475
  *
374
- * const re = new RRegex("'([^']+)'\s+\((\d{4})\)")
375
- * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
376
- * const caps = re.captures(text)
377
- * expect(caps.get[1].value).toBe("Citizen Kane")
378
- * expect(caps.get[2].value).toBe("1941")
379
- * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
380
- * ```
476
+ * This method will *not* copy the text given.
381
477
  *
382
- * Note that the full match is at capture group `0`. Each subsequent
383
- * capture group is indexed by the order of its opening `(`.
478
+ * # Example
384
479
  *
385
- * We can make this example a bit clearer by using *named* capture groups:
480
+ * Get the first two words in some text:
386
481
  *
387
482
  * ```typescript
388
483
  * import { RRegex } from "rregex"
389
484
  *
390
- * const re = new RRegex("'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)")
391
- * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
392
- * const caps = re.captures(text)
393
- * expect(caps.name["title"].value).toBe("Citizen Kane")
394
- * expect(caps.name["year"].value).toBe("1941")
395
- * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
485
+ * const re = new RRegex(r"\W+")
486
+ * const fields = re.splitn("Hey! How are you?", 3)
487
+ * expect(fields).toEqual(["Hey", "How", "are you?"])
396
488
  * ```
397
- *
398
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
489
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
399
490
  * @param {string} text - The string against which to match the regular expression
400
- * @returns {Captures|undefined}
491
+ * @param {number} limit - Max number result elements
492
+ * @returns {string[]}
401
493
  */
402
- captures(text) {
494
+ splitn(text, limit) {
403
495
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
404
496
  const len0 = WASM_VECTOR_LEN;
405
- const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
497
+ const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
498
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
499
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
500
+ return v2;
501
+ }
502
+ /**
503
+ * Returns the regular expression into a high level intermediate
504
+ * representation.
505
+ * @returns {any}
506
+ */
507
+ syntax() {
508
+ const ret = wasm.rregex_syntax(this.__wbg_ptr);
406
509
  if (ret[2]) {
407
510
  throw takeFromExternrefTable0(ret[1]);
408
511
  }
409
512
  return takeFromExternrefTable0(ret[0]);
410
513
  }
411
514
  /**
412
- * Returns a list with all the non-overlapping capture groups matched
413
- * in `text`. This is operationally the same as `findAll`, except it
414
- * returns information about capturing group matches.
415
- *
416
- * # Example
417
- *
418
- * We can use this to find all movie titles and their release years in
419
- * some text, where the movie is formatted like "'Title' (xxxx)":
420
- *
421
- * ```typescript
422
- * import { RRegex } from "rregex"
515
+ * Returns the same as find, but starts the search at the given
516
+ * offset.
423
517
  *
424
- * const re = new RRegex("'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)")
425
- * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
426
- * for caps of re.captures_iter(text) {
427
- * console.log(
428
- * "Movie:", caps.name["title"].value, ","
429
- * "Released:", caps.name["year"].value
430
- * );
431
- * }
432
- * // Output:
433
- * // Movie: Citizen Kane, Released: 1941
434
- * // Movie: The Wizard of Oz, Released: 1939
435
- * // Movie: M, Released: 1931
436
- * ```
518
+ * The significance of the starting point is that it takes the surrounding
519
+ * context into consideration. For example, the `\A` anchor can only
520
+ * match when `start == 0`.
437
521
  *
438
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
522
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
439
523
  * @param {string} text - The string against which to match the regular expression
440
- * @returns {Captures[]}
524
+ * @param {number} start - Zero-based index at which to start matching
525
+ * @returns {Match}
441
526
  */
442
- capturesAll(text) {
527
+ findAt(text, start) {
443
528
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
444
529
  const len0 = WASM_VECTOR_LEN;
445
- const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
530
+ const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
446
531
  if (ret[2]) {
447
532
  throw takeFromExternrefTable0(ret[1]);
448
533
  }
449
534
  return takeFromExternrefTable0(ret[0]);
450
535
  }
451
- /**
452
- * Returns the number of captures.
453
- *
454
- * This includes all named and unnamed groups, including the implicit
455
- * unnamed group that is always present and corresponds to the entire match.
456
- *
457
- * Since the implicit unnamed group is always included in this length, the
458
- * length returned is guaranteed to be greater than zero.
459
- *
460
- * ## Example
461
- *
462
- * ```typescript
463
- * import { RRegex } from "rregex"
464
- *
465
- * const re1 = new RRegex("(?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2})")
466
- * expect(re1.capturesLength()).toEqual(4)
467
- *
468
- * const re2 = new RRegex("foo")
469
- * expect(re2.capturesLength()).toEqual(1)
470
- *
471
- * const re3 = new RRegex("(foo)")
472
- * expect(re3.capturesLength()).toEqual(2)
473
- *
474
- * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
475
- * expect(re4.capturesLength()).toEqual(5)
476
- *
477
- * const re5 = new RRegex("[a&&b]")
478
- * expect(re5.capturesLength()).toEqual(1)
479
- * ```
480
- *
481
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
482
- * @returns {number}
483
- */
484
- capturesLength() {
485
- const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
486
- return ret >>> 0;
487
- }
488
536
  /**
489
537
  * Replaces the leftmost-first match with the replacement provided.
490
538
  * The replacement can be a regular string (where `$N` and `$name` are
@@ -577,197 +625,149 @@ export class RRegex {
577
625
  }
578
626
  }
579
627
  /**
580
- * Replaces at most `limit` non-overlapping matches in `text` with the
581
- * replacement provided. If `limit` is 0, then all non-overlapping matches
582
- * are replaced.
583
- *
584
- * See the documentation for `replace` for details on how to access
585
- * capturing group matches in the replacement string.
586
- *
587
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
588
- * @param {string} text - The string against which to match the regular expression
589
- * @param {number} limit - Max number of replacement
590
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
591
- * @returns {string}
592
- */
593
- replacen(text, limit, rep) {
594
- let deferred3_0;
595
- let deferred3_1;
596
- try {
597
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
598
- const len0 = WASM_VECTOR_LEN;
599
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
600
- const len1 = WASM_VECTOR_LEN;
601
- const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
602
- deferred3_0 = ret[0];
603
- deferred3_1 = ret[1];
604
- return getStringFromWasm0(ret[0], ret[1]);
605
- } finally {
606
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
607
- }
608
- }
609
- /**
610
- * Replaces all non-overlapping matches in `text` with the replacement
611
- * provided. This is the same as calling `replacen` with `limit` set to
612
- * `0`.
613
- *
614
- * See the documentation for `replace` for details on how to access
615
- * capturing group matches in the replacement string.
616
- *
617
- * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
618
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
619
- * @param {string} text - The string against which to match the regular expression
620
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
621
- * @returns {string}
622
- */
623
- replaceAll(text, rep) {
624
- let deferred3_0;
625
- let deferred3_1;
626
- try {
627
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
628
- const len0 = WASM_VECTOR_LEN;
629
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
630
- const len1 = WASM_VECTOR_LEN;
631
- const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
632
- deferred3_0 = ret[0];
633
- deferred3_1 = ret[1];
634
- return getStringFromWasm0(ret[0], ret[1]);
635
- } finally {
636
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
637
- }
638
- }
639
- /**
640
- * Returns an iterator of substrings of `text` delimited by a match of the
641
- * regular expression. Namely, each element of the iterator corresponds to
642
- * text that *isn't* matched by the regular expression.
628
+ * Returns the capture groups corresponding to the leftmost-first
629
+ * match in `text`. Capture group `0` always corresponds to the entire
630
+ * match. If no match is found, then `undefined` is returned.
643
631
  *
644
- * This method will *not* copy the text given.
632
+ * You should only use `captures` if you need access to the location of
633
+ * capturing group matches. Otherwise, `find` is faster for discovering
634
+ * the location of the overall match.
645
635
  *
646
- * # Example
636
+ * # Examples
647
637
  *
648
- * To split a string delimited by arbitrary amounts of spaces or tabs:
638
+ * Say you have some text with movie names and their release years,
639
+ * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
640
+ * looking like that, while also extracting the movie name and its release
641
+ * year separately.
649
642
  *
650
643
  * ```typescript
651
644
  * import { RRegex } from "rregex"
652
645
  *
653
- * const re = new RRegex(r"[ \t]+")
654
- * const fields = re.split("a b c d e")
655
- * expect(fields).toEqual(["a", "b", "c", "d", "e"])
646
+ * const re = new RRegex("'([^']+)'\s+\((\d{4})\)")
647
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
648
+ * const caps = re.captures(text)
649
+ * expect(caps.get[1].value).toBe("Citizen Kane")
650
+ * expect(caps.get[2].value).toBe("1941")
651
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
656
652
  * ```
657
653
  *
658
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
654
+ * Note that the full match is at capture group `0`. Each subsequent
655
+ * capture group is indexed by the order of its opening `(`.
656
+ *
657
+ * We can make this example a bit clearer by using *named* capture groups:
658
+ *
659
+ * ```typescript
660
+ * import { RRegex } from "rregex"
661
+ *
662
+ * const re = new RRegex("'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)")
663
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
664
+ * const caps = re.captures(text)
665
+ * expect(caps.name["title"].value).toBe("Citizen Kane")
666
+ * expect(caps.name["year"].value).toBe("1941")
667
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
668
+ * ```
669
+ *
670
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
659
671
  * @param {string} text - The string against which to match the regular expression
660
- * @returns {string[]}
672
+ * @returns {Captures|undefined}
661
673
  */
662
- split(text) {
674
+ captures(text) {
663
675
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
664
676
  const len0 = WASM_VECTOR_LEN;
665
- const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
666
- var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
667
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
668
- return v2;
677
+ const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
678
+ if (ret[2]) {
679
+ throw takeFromExternrefTable0(ret[1]);
680
+ }
681
+ return takeFromExternrefTable0(ret[0]);
669
682
  }
670
683
  /**
671
- * Returns an iterator of at most `limit` substrings of `text` delimited
672
- * by a match of the regular expression. (A `limit` of `0` will return no
673
- * substrings.) Namely, each element of the iterator corresponds to text
674
- * that *isn't* matched by the regular expression. The remainder of the
675
- * string that is not split will be the last element in the iterator.
676
- *
677
- * This method will *not* copy the text given.
684
+ * Returns an array for each successive non-overlapping match in `text``,
685
+ * returning the start and end byte indices with respect to `text`.
678
686
  *
679
687
  * # Example
680
688
  *
681
- * Get the first two words in some text:
689
+ * Find the start and end location of every word with exactly 13 Unicode
690
+ * word characters:
682
691
  *
683
692
  * ```typescript
684
693
  * import { RRegex } from "rregex"
685
694
  *
686
- * const re = new RRegex(r"\W+")
687
- * const fields = re.splitn("Hey! How are you?", 3)
688
- * expect(fields).toEqual(["Hey", "How", "are you?"])
695
+ * const text = "Retroactively relinquishing remunerations is reprehensible."
696
+ * const matches = new RRegex("\b\w{13}\b").findAll(text)
689
697
  * ```
690
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
698
+ *
699
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
691
700
  * @param {string} text - The string against which to match the regular expression
692
- * @param {number} limit - Max number result elements
693
- * @returns {string[]}
701
+ * @returns {Match}
694
702
  */
695
- splitn(text, limit) {
703
+ findAll(text) {
696
704
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
697
705
  const len0 = WASM_VECTOR_LEN;
698
- const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
699
- var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
700
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
701
- return v2;
706
+ const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
707
+ if (ret[2]) {
708
+ throw takeFromExternrefTable0(ret[1]);
709
+ }
710
+ return takeFromExternrefTable0(ret[0]);
702
711
  }
703
712
  /**
704
- * Returns the end location of a match in the text given.
705
- *
706
- * This method may have the same performance characteristics as
707
- * `isMatch`, except it provides an end location for a match. In
708
- * particular, the location returned *may be shorter* than the proper end
709
- * of the leftmost-first match that you would find via `Regex.find`.
713
+ * Returns true if and only if there is a match for the regex in the
714
+ * string given.
710
715
  *
711
- * Note that it is not guaranteed that this routine finds the shortest or
712
- * "earliest" possible match. Instead, the main idea of this API is that
713
- * it returns the offset at the point at which the internal regex engine
714
- * has determined that a match has occurred. This may vary depending on
715
- * which internal regex engine is used, and thus, the offset itself may
716
- * change.
716
+ * It is recommended to use this method if all you need to do is test
717
+ * a match, since the underlying matching engine may be able to do less
718
+ * work.
717
719
  *
718
720
  * # Example
719
721
  *
720
- * Typically, `a+` would match the entire first sequence of `a` in some
721
- * text, but `shortest_match` can give up as soon as it sees the first
722
- * `a`.
722
+ * Test if some text contains at least one word with exactly 13
723
+ * Unicode word characters:
723
724
  *
724
725
  * ```typescript
725
726
  * import { RRegex } from "rregex"
726
727
  *
727
- * const text = "aaaaa"
728
- * const = new RRegex("a+").shortest_match(text)
729
- * expect(pos).toBe(1)
728
+ * const text = "I categorically deny having triskaidekaphobia."
729
+ * expect(new RRegex("\b\w{13}\b").is_match(text)).toBe(true)
730
730
  * ```
731
731
  *
732
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
732
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
733
733
  * @param {string} text - The string against which to match the regular expression
734
- * @returns {number|undefined}
734
+ * @return {boolean}
735
735
  */
736
- shortestMatch(text) {
736
+ isMatch(text) {
737
737
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
738
738
  const len0 = WASM_VECTOR_LEN;
739
- const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
740
- return ret === 0x100000001 ? undefined : ret;
739
+ const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
740
+ return ret !== 0;
741
741
  }
742
742
  /**
743
- * Returns the same as `shortest_match`, but starts the search at the
744
- * given offset.
743
+ * Replaces at most `limit` non-overlapping matches in `text` with the
744
+ * replacement provided. If `limit` is 0, then all non-overlapping matches
745
+ * are replaced.
745
746
  *
746
- * The significance of the starting point is that it takes the surrounding
747
- * context into consideration. For example, the `\A` anchor can only match
748
- * when `start == 0`.
749
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
747
+ * See the documentation for `replace` for details on how to access
748
+ * capturing group matches in the replacement string.
749
+ *
750
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
750
751
  * @param {string} text - The string against which to match the regular expression
751
- * @param {number} start - Zero-based index at which to start matching
752
- * @returns {number|undefined}
753
- */
754
- shortestMatchAt(text, start) {
755
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
756
- const len0 = WASM_VECTOR_LEN;
757
- const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
758
- return ret === 0x100000001 ? undefined : ret;
759
- }
760
- /**
761
- * Returns the regular expression into a high level intermediate
762
- * representation.
763
- * @returns {any}
752
+ * @param {number} limit - Max number of replacement
753
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
754
+ * @returns {string}
764
755
  */
765
- syntax() {
766
- const ret = wasm.rregex_syntax(this.__wbg_ptr);
767
- if (ret[2]) {
768
- throw takeFromExternrefTable0(ret[1]);
756
+ replacen(text, limit, rep) {
757
+ let deferred3_0;
758
+ let deferred3_1;
759
+ try {
760
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
761
+ const len0 = WASM_VECTOR_LEN;
762
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
763
+ const len1 = WASM_VECTOR_LEN;
764
+ const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
765
+ deferred3_0 = ret[0];
766
+ deferred3_1 = ret[1];
767
+ return getStringFromWasm0(ret[0], ret[1]);
768
+ } finally {
769
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
769
770
  }
770
- return takeFromExternrefTable0(ret[0]);
771
771
  }
772
772
  /**
773
773
  * Returns a string representing the regular expression
@@ -842,43 +842,6 @@ export class RRegexSet {
842
842
  RRegexSetFinalization.register(this, this.__wbg_ptr, this);
843
843
  return this;
844
844
  }
845
- /**
846
- * Returns true if and only if one of the regexes in this set matches
847
- * the text given.
848
- *
849
- * This method should be preferred if you only need to test whether any
850
- * of the regexes in the set should match, but don't care about *which*
851
- * regexes matched. This is because the underlying matching engine will
852
- * quit immediately after seeing the first match instead of continuing to
853
- * find all matches.
854
- *
855
- * Note that as with searches using `Regex`, the expression is unanchored
856
- * by default. That is, if the regex does not start with `^` or `\A`, or
857
- * end with `$` or `\z`, then it is permitted to match anywhere in the
858
- * text.
859
- *
860
- * # Example
861
- *
862
- * Tests whether a set matches some text:
863
- *
864
- * ```typescript
865
- * import { RegexSet } from "rregex"
866
- *
867
- * const set = new RegexSet(["\w+", "\d+"])
868
- * expect(set.is_match("foo")).toBe(true)
869
- * expect(!set.is_match("☃")).toBe(false)
870
- * ```
871
- *
872
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
873
- * @param {string} text - The string against which to match the regular expression
874
- * @return {boolean}
875
- */
876
- isMatch(text) {
877
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
878
- const len0 = WASM_VECTOR_LEN;
879
- const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
880
- return ret !== 0;
881
- }
882
845
  /**
883
846
  * Returns the set of regular expressions that match in the given text.
884
847
  *
@@ -925,57 +888,94 @@ export class RRegexSet {
925
888
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
926
889
  return v2;
927
890
  }
891
+ /**
892
+ * Returns true if and only if one of the regexes in this set matches
893
+ * the text given.
894
+ *
895
+ * This method should be preferred if you only need to test whether any
896
+ * of the regexes in the set should match, but don't care about *which*
897
+ * regexes matched. This is because the underlying matching engine will
898
+ * quit immediately after seeing the first match instead of continuing to
899
+ * find all matches.
900
+ *
901
+ * Note that as with searches using `Regex`, the expression is unanchored
902
+ * by default. That is, if the regex does not start with `^` or `\A`, or
903
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
904
+ * text.
905
+ *
906
+ * # Example
907
+ *
908
+ * Tests whether a set matches some text:
909
+ *
910
+ * ```typescript
911
+ * import { RegexSet } from "rregex"
912
+ *
913
+ * const set = new RegexSet(["\w+", "\d+"])
914
+ * expect(set.is_match("foo")).toBe(true)
915
+ * expect(!set.is_match("☃")).toBe(false)
916
+ * ```
917
+ *
918
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
919
+ * @param {string} text - The string against which to match the regular expression
920
+ * @return {boolean}
921
+ */
922
+ isMatch(text) {
923
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
924
+ const len0 = WASM_VECTOR_LEN;
925
+ const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
926
+ return ret !== 0;
927
+ }
928
928
  }
929
929
 
930
930
  const imports = {
931
931
  wbg: {
932
- __wbg_buffer_61b7ce01341d7f88: function(arg0) {
932
+ __wbg_buffer_609cc3eee51ed158: function(arg0) {
933
933
  const ret = arg0.buffer;
934
934
  return ret;
935
935
  },
936
- __wbg_fromCodePoint_ef89154c4db48bdf: function() { return handleError(function (arg0) {
936
+ __wbg_fromCodePoint_f37c25c172f2e8b5: function() { return handleError(function (arg0) {
937
937
  const ret = String.fromCodePoint(arg0 >>> 0);
938
938
  return ret;
939
939
  }, arguments) },
940
- __wbg_from_d68eaa96dba25449: function(arg0) {
940
+ __wbg_from_2a5d3e218e67aa85: function(arg0) {
941
941
  const ret = Array.from(arg0);
942
942
  return ret;
943
943
  },
944
- __wbg_get_9aa3dff3f0266054: function(arg0, arg1) {
944
+ __wbg_get_b9b93047fe3cf45b: function(arg0, arg1) {
945
945
  const ret = arg0[arg1 >>> 0];
946
946
  return ret;
947
947
  },
948
- __wbg_length_d65cf0786bfc5739: function(arg0) {
948
+ __wbg_length_e2d2a49132c1b256: function(arg0) {
949
949
  const ret = arg0.length;
950
950
  return ret;
951
951
  },
952
- __wbg_new_254fa9eac11932ae: function() {
953
- const ret = new Array();
952
+ __wbg_new_405e22f390576ce2: function() {
953
+ const ret = new Object();
954
954
  return ret;
955
955
  },
956
- __wbg_new_3ff5b33b1ce712df: function(arg0) {
957
- const ret = new Uint8Array(arg0);
956
+ __wbg_new_78feb108b6472713: function() {
957
+ const ret = new Array();
958
958
  return ret;
959
959
  },
960
- __wbg_new_688846f374351c92: function() {
961
- const ret = new Object();
960
+ __wbg_new_a12002a7f91c75be: function(arg0) {
961
+ const ret = new Uint8Array(arg0);
962
962
  return ret;
963
963
  },
964
- __wbg_newwithbyteoffsetandlength_ba35896968751d91: function(arg0, arg1, arg2) {
964
+ __wbg_newwithbyteoffsetandlength_d97e637ebe145a9a: function(arg0, arg1, arg2) {
965
965
  const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
966
966
  return ret;
967
967
  },
968
- __wbg_push_6edad0df4b546b2c: function(arg0, arg1) {
968
+ __wbg_push_737cfc8c1432c2c6: function(arg0, arg1) {
969
969
  const ret = arg0.push(arg1);
970
970
  return ret;
971
971
  },
972
- __wbg_set_1d80752d0d5f0b21: function(arg0, arg1, arg2) {
972
+ __wbg_set_37837023f3d740e8: function(arg0, arg1, arg2) {
973
973
  arg0[arg1 >>> 0] = arg2;
974
974
  },
975
975
  __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
976
976
  arg0[arg1] = arg2;
977
977
  },
978
- __wbg_set_4e647025551483bd: function() { return handleError(function (arg0, arg1, arg2) {
978
+ __wbg_set_bb8cecf6a62b9f46: function() { return handleError(function (arg0, arg1, arg2) {
979
979
  const ret = Reflect.set(arg0, arg1, arg2);
980
980
  return ret;
981
981
  }, arguments) },
@@ -1054,6 +1054,6 @@ export const metadata = {
1054
1054
  ],
1055
1055
  "homepage": "http://rregex.dev",
1056
1056
  "repository": "https://github.com/2fd/rregex",
1057
- "regex": "1.11.1",
1058
- "regex-syntax": "0.8.5"
1057
+ "regex": "1.12.4",
1058
+ "regex-syntax": "0.8.11"
1059
1059
  }