INNER CODE UNIT · TypeScript

findAddressInText

postalsys/postal-mime · src/address-parser.ts:37

function findAddressInText(text: string): AddressMatch | null {
    NON_SPACE_TOKEN_REGEX.lastIndex = 0;

    let match: RegExpExecArray | null;
    while ((match = NON_SPACE_TOKEN_REGEX.exec(text))) {
        const token = match[0];
        const at = token.indexOf('@');

        // `\b[^@\s]+@` needs at least one character before the '@'
        let start = 0;
        while (start < at && !WORD_CHAR_REGEX.test(token.charAt(start))) {
            start++;
        }
        if (start >= at) {
            continue;
        }

        // `[^\s]+\b` needs at least one character after the '@', ending on a word character

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…