yet another RegEx issue

I have a TextArea subclass the needs to highlight a small subset of words
this is basically the code [fired off on TextChange event, and TextArea open)

if should highlight EVERY occurance of each of the listed words… but at best it is only doing the LAST one
I should see that DEBUG "S= line for each word it finds regardless if it is between Xstart and XEnd

zRegEx.SearchPattern = pattern
match = zRegEx.Search(Me.Text)
debug "Search "+Str(match=Nil)+" : "+pattern
debug "Text"
debug "----------------------------------------------------"
debug Me.Text
debug "----------------------------------------------------"
If match <> Nil Then
result = match.SubExpressionString(0)
xStart = match.SubExpressionStartB(0)
xEnd   = xStart+Len(result)-1
debug "S="+Str(xstart)+" E="+Str(xend)+" F="+Str(firstChar)+" to "+Str(lastChar)+" R="+result
If (xstart>=firstChar And xstart<=lastChar) Or (xend>=firstChar And xend<=lastChar) Then 
If firstChar>xStart Then xStart=firstChar
If lastChar <xEnd   Then xEnd  =lastChar
If xEnd>=xStart Then 
Me.SelStart     = xStart
Me.SelLength    = xEnd
Me.SelTextColor = optionColor
Me.SelBold      = optionBold
Me.SelItalic    = optionItalic
Me.SelUnderline = optionUnderline
Me.SelTextFont  = Me.TextFont
debug me.SelText
End If
End If
End If
match = zRegEx.Search
Loop Until match Is Nil

the log shows

Search False : (?i)\\b(@freddy|@Barney|@Dave|@Fred)\\b
0askldjfalsdkf asdas 
1adsfasdfrq23412 3
2this is a test @freddy @Dave @Dave
3askldjfalsdkf asdas 
4adsfasdfrq23412 3
5this is a test
6askldjfalsdkf asdas 
7adsfasdfrq23412 3
8this is a test
9askldjfalsdkf asdas 
10adsfasdfrq23412 3
11this is a test
12askldjfalsdkf asdas @Dave
13adsfasdfrq23412 3@Dave
14this is a test
S=297 E=301 F=0 to 175 R=@Dave  <--- this is the LAST occurance... it is NOT touching any others

Can you do multi-selection with SelStart and SelLength???

not sure I understand your question?

if you are thinking it DOES highlight each item, but because SelStart is changing only the last one remains, that shouldn’t be the case as the attributes are assigned as it scans the text… also that debug statement I mentioned should appear in the log multiple times, but it only appears once (and sometimes not at all)

the issue was with the RegEx itself
seems a simple (well simple for Kem maybe, but it took me hours of trial and error)


to this


and it now works perfectly :slight_smile: