Sometimes Xojo makes my head really hurt. I’ve got this old regex from Joe Strout to split strings with a regex:
[code]Protected Function SplitByRegEx(source As String, delimPattern As String) As String()
Dim out(-1) As String
Dim startPos As Integer
Dim re As New RegEx
re.SearchPattern = delimPattern
Dim rm As RegExMatch = re.Search(source)
while rm <> nil
out.Append MidB(source, startPos + 1, rm.SubExpressionStartB(0) - startPos)
startPos = re.SearchStartPosition
rm = re.Search
wend
if startPos < source.LenB then out.Append MidB(source, startPos + 1)
return out
End Function[/code]
Yesterday I saw this code failing for one single case. Since I’m using the code to split mails into it’s parts the delimPattern string HAS to be there. Now the odd thing: after making an example in Xojo 2013r2 the code works. When I exchange the code to use MBS everything also works:
[code]Protected Function SplitByRegEx(source As String, delimPattern As String) As String()
Dim out(-1) As String
Dim re As New RegExMBS
if re.Compile(delimPattern) then
dim start as integer = 0
while re.Execute(source, start) > 0 and start < lenb(source)
dim p as integer = re.Offset(0)
out.Append midb(source, start + 1, p - start)
start = re.Offset(1)
wend
end if
return out
End Function[/code]
Delimpatterns are usually quite simple like: ------------070105050805040109060307|------------070105050805040109060307–
The source in my test case is
[quote]This is a multi-part message in MIME format.
--------------070105050805040109060307
Content-Type: multipart/alternative;
boundary="------------040103000006050701000807"
--------------040103000006050701000807
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Guten Tag[/quote]
Do I have a senior moment? Does anyone see what is wrong with my code?