diff --git a/src/annotations/autolinks.ts b/src/annotations/autolinks.ts index faa112c..55ca10c 100644 --- a/src/annotations/autolinks.ts +++ b/src/annotations/autolinks.ts @@ -72,7 +72,9 @@ export class Autolinks implements Disposable { if (ref.messageRegex === undefined) { ref.messageRegex = new RegExp( - `(?<=^|\\s|\\()(${ref.prefix}([${ref.alphanumeric ? '\\w' : '0-9'}]+))\\b`, + `(?<=^|\\s|\\(|\\\\\\[)(${Strings.escapeRegex(ref.prefix)}([${ + ref.alphanumeric ? '\\w' : '0-9' + }]+))\\b`, ref.ignoreCase ? 'gi' : 'g', ); } @@ -148,7 +150,7 @@ export class Autolinks implements Disposable { try { if (ref.messageMarkdownRegex === undefined) { ref.messageMarkdownRegex = new RegExp( - `(?<=^|\\s|\\()(${Strings.escapeMarkdown(ref.prefix).replace(/\\/g, '\\\\')}([${ + `(?<=^|\\s|\\(|\\\\\\[)(${Strings.escapeRegex(Strings.escapeMarkdown(ref.prefix))}([${ ref.alphanumeric ? '\\w' : '0-9' }]+))\\b`, ref.ignoreCase ? 'gi' : 'g', diff --git a/src/system/string.ts b/src/system/string.ts index 00e6a4a..0bbe923 100644 --- a/src/system/string.ts +++ b/src/system/string.ts @@ -39,6 +39,10 @@ export namespace Strings { return s.replace(markdownQuotedRegex, '\t\n> '); } + export function escapeRegex(s: string) { + return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + } + export function getCommonBase(s1: string, s2: string, delimiter: string) { let char; let index = 0;