How does a RE fully match a word that should not be highlighted if there are letters or words before and after it

28 Views Asked by At
const keywords =  [Stop,.............]

monaco.languages.register({ id: "mySpecialLanguage" });

monaco.languages.setMonarchTokensProvider("mySpecialLanguage", {
    tokenizer: {
        root: [
            [/(?<!\w)Stop(?!\w)/, 'keyword']
        ],
    },
});

monaco.editor.defineTheme("myCoolTheme", {
    base: "vs",
    inherit: false,
    rules: [
        { token: 'keyword', foreground: 'f1d710' },
    ],
    colors: {
        "editor.foreground": "#000000",
    },
});


monaco.editor.create(document.getElementById("container"), {
    theme: "myCoolTheme",
    value: `Stop
QdStop
qdStop
11Stop
StopSS
Stop11
Stopdd 
    `,
    language: "mySpecialLanguage",
});

enter image description here

I expected all keywords to be highlighted, but now Stop is included in the keywords list, but words ending in Stop will still be highlighted

The effect at the beginning of Stop is correct, but the effect at the end of Stop is wrong and should be shown in black, not yellow

How do I make it highlighted as a keyword only for Stop words, it shouldn't be highlighted if there are letters or words before and after it

0

There are 0 best solutions below