Skip to content

Commit 91f90be

Browse files
committed
bugfix:正则表达式字符转义
1 parent 70dc796 commit 91f90be

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ST.Library.UI.STTextBox/Implementation/StyleMonitor/SelectionStyleMonitor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ public void OnSelectionChanged(TextManager textManager, int nStart, int nLen) {
4141
}
4242
return false;
4343
});
44-
if (!string.IsNullOrEmpty(strKey)) {
44+
if (!string.IsNullOrEmpty(strKey)) {
4545
string strText = textManager.GetText();
4646
List<TextStyleRange> lst = new List<TextStyleRange>();
47-
foreach (Match m in Regex.Matches(strText, "\\b" + strKey + "\\b")) {
47+
if ("* . ? + $ ^ [ ] ( ) { } | \\ /".Split(' ').Contains(strKey))
48+
{
49+
strKey = "\\" + strKey;
50+
}
51+
foreach (Match m in Regex.Matches(strText, "\\b" + strKey + "\\b")) { // * . ? + $ ^ [ ] ( ) { } | \ /
4852
lst.Add(new TextStyleRange() {
4953
Index = m.Index,
5054
Length = m.Length,

0 commit comments

Comments
 (0)