Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit f3a6fcb

Browse files
committed
Escape regex expressions from keywords
1 parent 6dbf7b4 commit f3a6fcb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Utils/RegexKeywordsHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static Regex GetRegexFromKeywords(List<string> keywords)
3232
}
3333

3434
return new Regex(
35-
@$"\b({string.Join("|", keywords)})\b",
35+
@$"\b({string.Join("|", keywords.Select(Regex.Escape))})\b",
3636
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
3737
}
3838

@@ -48,7 +48,7 @@ public static Regex GetFunctionRegex(string[] keywords)
4848
}
4949

5050
return new Regex(
51-
@$"\b(?<!\.)({string.Join("|", keywords)})\b",
51+
@$"\b(?<!\.)({string.Join("|", keywords.Select(Regex.Escape))})\b",
5252
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
5353
}
5454

@@ -63,7 +63,7 @@ public static Regex GetMethodRegex(List<string> keywords)
6363
}
6464

6565
return new Regex(
66-
@$"\b(?<=[^\s]+\.)({string.Join("|", keywords)})\b",
66+
@$"\b(?<=[^\s]+\.)({string.Join("|", keywords.Select(Regex.Escape))})\b",
6767
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
6868
}
6969
}

0 commit comments

Comments
 (0)