using regEx

Byak@

Active Member
Licensed User
i have string
B4X:
test test(test[COLOR=Red],[/COLOR]test[COLOR=Red],[/COLOR]test()[COLOR=Red],[/COLOR]")"[COLOR=Red],[/COLOR]"("[COLOR=Red],[/COLOR]"test,"[COLOR=Red],[/COLOR]",test") test
i was replace ',' to '&"*"&'
result must be
B4X:
test test(test[COLOR=Red]&"*"&[/COLOR]test[COLOR=Red]&"*"&[/COLOR]test()[COLOR=Red]&"*"&[/COLOR]")"[COLOR=Red]&"*"&[/COLOR]"("[COLOR=Red]&"*"&[/COLOR]"test,"[COLOR=Red]&"*"&[/COLOR]",test") test
i'm try to do it with basic's string methods but can't.for first i want select test,test,test(),")","(","test,",",test"

B4X:
'replace ',' as '&"*"&'
newcode="test test(test,test,test(),")","(","test,",",test") test"
lastc="test("

i=StrIndexOf(newcode,lastc,i)
i=i+StrLength(lastc)
'find ')'
i1=StrIndexOf(newcode,")",i)
'check for '"...)..."'
i2=StrIndexOf(newcode,Chr(34),i)
i3=StrIndexOf(newcode,Chr(34),i2+1)
s=0
If i1>i2 AND i1<i3 Then s=1
Do While s=1
s=0
i1=StrIndexOf(newcode,")",i3)
i2=StrIndexOf(newcode,Chr(34),i3+1)
If i1<>-1 AND i2<>-1 Then
i3=StrIndexOf(newcode,Chr(34),i2+1)
If i1>i2 AND i1<i3 Then s=1
End If
Loop
'find '('
i2=StrIndexOf(newcode,"(",i)
'check for '"...(..."'
i3=StrIndexOf(newcode,Chr(34),i)
i4=StrIndexOf(newcode,Chr(34),i3+1)
s=0
If i2>i3 AND i2<i4 Then s=1
Do While s=1
s=0
i2=StrIndexOf(newcode,"(",i4)
i3=StrIndexOf(newcode,Chr(34),i4+1)
If i2<>-1 AND i3<>-1 Then
i4=StrIndexOf(newcode,Chr(34),i3+1)
If i2>i3 AND i2<i4 Then s=1
End If
Loop
'find index of last ')'
If i2<>-1 Then
Do While i2<i1
i3=i1
i1=StrIndexOf(newcode,")",i3+1)
i2=StrIndexOf(newcode,"(",i3+1)
If i2=-1 Then i2=i1+1
Loop
End If
Msgbox(SubString(newcode,i,i1-i))
i'm start reading manuals for RegEx but :BangHead:
help me please!
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub App_Start
    q = Chr(34)
    'str = "test test(test,test,test(),")","(","test,",",test") test"
    str = "test test(test,test,test(),"&q&")"&q&","&q&"("&q&","&q&"test,"&q&","&q&",test"&q&") test"
    inQuote = False
    i = 0
    Do While i < StrLength(str)
        c = StrAt(str, i)
        If c = Chr(34) Then 
            inQuote = Not(inQuote)
        Else If c = "," AND inQuote = False Then
            str = StrRemove(str, i, 1)
            str = StrInsert(str, i, "&"&q&"*"&q&"&")
            i = i + 3
        End If
        i = i + 1
    Loop
    Msgbox(str)
End Sub
 

Byak@

Active Member
Licensed User
Thanks Erel but i'm already do it :-[
i want foud faster method...
 
Top