MCPcopy
hub / github.com/vercel-labs/just-bash / ConstantRegex

Class ConstantRegex

packages/just-bash/src/regex/user-regex.ts:520–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

518 * Implements the same interface as UserRegex for consistency.
519 */
520export class ConstantRegex implements RegexLike {
521 private readonly _regex: RegExp;
522
523 constructor(regex: RegExp) {
524 this._regex = regex;
525 }
526
527 test(input: string): boolean {
528 if (this._regex.global) {
529 this._regex.lastIndex = 0;
530 }
531 return this._regex.test(input);
532 }
533
534 exec(input: string): RegExpExecArray | null {
535 return this._regex.exec(input);
536 }
537
538 match(input: string): RegExpMatchArray | null {
539 if (this._regex.global) {
540 this._regex.lastIndex = 0;
541 }
542 return input.match(this._regex);
543 }
544
545 replace(input: string, replacement: string | ReplaceCallback): string {
546 if (this._regex.global) {
547 this._regex.lastIndex = 0;
548 }
549 return input.replace(
550 this._regex,
551 replacement as (substring: string, ...args: unknown[]) => string,
552 );
553 }
554
555 split(input: string, limit?: number): string[] {
556 return input.split(this._regex, limit);
557 }
558
559 search(input: string): number {
560 return input.search(this._regex);
561 }
562
563 *matchAll(input: string): IterableIterator<RegExpMatchArray> {
564 if (!this._regex.global) {
565 throw new Error("matchAll requires global flag");
566 }
567 this._regex.lastIndex = 0;
568 let match = this._regex.exec(input);
569 while (match !== null) {
570 yield match;
571 if (match[0].length === 0) {
572 this._regex.lastIndex++;
573 }
574 match = this._regex.exec(input);
575 }
576 }
577

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…