Android Question RegEx.Split Maintain Case of the Split Elements

Mahares

Expert
Licensed User
Longtime User
This works well, but the split elements do not preserve the case.
B4X:
Dim sentence = "There is NO End to the end of the Covid19" As String 'works
    Dim pat As String ="end"   
    Dim l As List
    l.Initialize
    Dim m As Matcher
    m = Regex.Matcher2(pat, Regex.CASE_INSENSITIVE, sentence) 'Matcher2 not Matcher
    Do While m.Find
        Log(m.Match)
        l.Add(m.Match)
    Loop
    Log("-----")
    
    sentence=sentence.ToLowercase
    pat=pat.ToLowercase    
    Dim s() As String =Regex.Split(pat,sentence)
    For i=0 To s.Length -1
        Log(s(i))
    Next
Result:
there is no
to the
of the covid19
I like the result to be exactly as below in the sentence. How do we fix the pattern: to achieve the below result
There is NO
to the
of the Covid19
 

Mahares

Expert
Licensed User
Longtime User
Your code lowercases the string in line 13.
But if I do not lower case the sentence I get this as the split elements, which is missing one element
There is NO End to the
of the Covid19

I need the pattern to be either End or end
 
Upvote 0
Top