Function extract

  • Namespace

    StringUtils

    Extract all substrings from a string that match a given pattern.

    Parameters

    • str: string

      The input string.

    • pattern: RegExp

      The regular expression pattern to match substrings.

    Returns string[]

    An array containing all substrings that match the pattern.

    Example

    const originalString = "The quick brown fox jumps over the lazy dog";
    const pattern = /[aeiou]{2}/g; // Match two consecutive vowels
    const matchedSubstrings = extractSubstringsByPattern(originalString, pattern);
    console.log(matchedSubstrings);
    // Output: ["ui", "ow", "um", "ps", "eo", "er", "az"]

Generated using TypeDoc