Skip to content

Using regexp for words #5118

Answered by Jason3S
mikdiet asked this question in Q&A
Dec 26, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Here is a working example. It loads the words from words.txt in the same directory as cspell.config.mjs and expands them returning a custom dictionary called custom-words.

cspell.config.mjs

import { promises as fs } from 'fs';

function expand(pattern, options = { begin: '(', end: ')', sep: '|' }, start = 0) {
    const len = pattern.length;
    const parts = [];
    function push(word) {
        if (Array.isArray(word)) {
            parts.push(...word);
        } else {
            parts.push(word);
        }
    }
    let i = start;
    let curWord = '';
    while (i < len) {
        const ch = pattern[i++];
        if (ch === options.end) {
            break;
        }
        if (ch ===

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Jason3S
Comment options

Answer selected by mikdiet
@mikdiet
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants