let m = Regex.Match(X.Text, "\\b(select)|(where)|(from)\\b", RegexOptions.IgnoreCase)
선택 만 강조 표시되므로 문제가 내 Regex.Match 구문에있는 것 같지만 어디에서 볼 수 있습니까? 나의 현재 솔루션은 다음과 같이 찾고 alll의 변화와정규식 문자열 중 하나와 일치
: 나는 정규 표현식 테스트 베드를 사용하는 것이 좋습니다
module SQL_Highlighing
open System.Runtime.InteropServices
module Lock =
[<DllImport(@"User32", CharSet = CharSet.Ansi, SetLastError = false, ExactSpelling = true)>]
extern void LockWindowUpdate(int hWnd)
open System.Text.RegularExpressions
open System.Drawing
type SyntaxRTB() =
inherit System.Windows.Forms.RichTextBox()
override X.OnTextChanged(e : System.EventArgs) =
base.OnTextChanged(e); X.ColorTheKeyWords()
member X.ColorTheKeyWords() =
let HL s c =
let color(m : Match, color : Color) =
X.SelectionStart <- m.Index
X.SelectionLength <- m.Length
X.SelectionColor <- color
Regex.Matches(X.Text, "\\b" + s + "\\b", RegexOptions.IgnoreCase) |> fun mx ->
for m in mx do if (m.Success) then color(m,c)
let SelectionAt = X.SelectionStart
Lock.LockWindowUpdate(X.Handle.ToInt32())
HL "(select)|(where)|(from)|(top)|(order)|(group)|(by)|(as)|(null)" Color.Blue
HL "(join)|(left)|(inner)|(outer)|(right)|(on)" Color.Red
HL "(and)|(or)|(not)" Color.DarkSlateGray
HL "(case)|(when)|(then)|(else)|(end)" Color.BurlyWood
HL "(cast)|(nvarchar)|(bit)" Color.BlueViolet
HL "(datepart)" Color.Teal
X.SelectionStart <- SelectionAt
X.SelectionLength <- 0
X.SelectionColor <- Color.Black
Lock.LockWindowUpdate(0)
귀하의 문제와 관련이 있다고 의심 스럽지만 P/Invoke 서명이 잘못되었습니다. 그것은'extern bool LockWindowUpdate (nativeint hWnd)'이어야하고'SetLastError'는'false'로 설정되어야합니다. – ildjarn
흠, 첫 번째 선택 부분 만 강조 표시됩니다. 대신'Regex.Matches'를 사용하십시오. 문제 (코드를 테스트하지 않은 경우) 일 수 있습니다. –
또한'\\ b's로 무엇을하려합니까? 정말로 입력 데이터에서 백 스페이스 리터럴을 기대하십니까? – ildjarn