RegEx and Unicode

I have text containing Unicode characters (like ,)
Now I want to search this text for single characters or words using RegEx and highlight the found matches.

my searchpattern: ("\b" + searchText + “\b”) for search on whole word only or just (“searchText”) for any match.

this is my search routine:

match = me.Search(m_inText)
while match <> nil

idx = match.SubExpressionStartB(0)
len = len(match.SubExpressionString(0))

range.index = idx
range.length = len

m_matches.Append(range)
match = me.Search()

wend

this function returns an array of ranges which I use with styled text to highlight all matching words/characters.
it is working ok as long as the text to search has no Unicode characters.

Problem: all highligted matches are shifted 1 to the right after an Unicode character in text.
e.g
text: meem
search for e
first e is highlighted correct, second e is not highlighted but charater m is highlighted.

any Help?

Characters whose code point > 127 can be represented by 2, 3, or 4 bytes in UTF-8. A single character will have a length of 1, but may have a LenB of 1, 2, 3, 4. This is important because SubSpressionStartB returns a byte position, not a character position, so you have to adjust accordingly.