Android Question Easy way to get each url on each line ( regex maybe ? )

tufanv

Expert
Licensed User
Longtime User
Hello,

I have a string like this:

B4X:
/var/www/xx.yy.com/public_html/files/qjax83: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/chyusc: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/7tyskq: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/bpjeu5: Win.Trojan.MSShellcode-7 FOUND
/var/www/xx.yy.com/public_html/files/q766jv: Win.Trojan.MSShellcode-7 FOUND
/var/www/xx.yy.com/public_html/files/lhie42: Doc.Malware.Valyria-6728957-0 FOUND

This string may be 100 lines or 6 lines it changes every day, I need to get the links of each line after files/ . For example for this string i need to get each link : qjax83,chyusc,7tyskq etc.. Is there an easy way to get these ? I tried to use substring etc but it is not optimal. Maybe possible with regex ?

Thanks
 

tufanv

Expert
Licensed User
Longtime User
SubString2 is enough.

B4X:
Dim Text As String = "/var/www/xx.yy.com/public_html/files/qjax83: Win.Trojan.B-468 FOUND"
Dim Link as String = Text.SubString2(37, 44)
:) yes but the url can change dynamically(path to file) so the positions can change..
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
    Dim Text As String = "/var/www/xx.yy.com/public_html/files/qjax83: Win.Trojan.B-468 FOUND"
    Dim StartPos, EndPos As Int
    StartPos = Text.LastIndexOf("/") + 1
    EndPos = Text.IndexOf(":")
    Dim Link As String = Text.SubString2(StartPos, EndPos)
    Log("link " & Link)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Dim Text As String = "/var/www/xx.yy.com/public_html/files/qjax83: Win.Trojan.B-468 FOUND"
Log(GetLink(Text))


Sub GetLink(Text As String) As String
    Dim StartPos, EndPos As Int
    StartPos = Text.LastIndexOf("/") + 1
    EndPos = Text.IndexOf(":")
    Return Text.SubString2(StartPos, EndPos)
End Sub
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
B4X:
Dim Text As String = "/var/www/xx.yy.com/public_html/files/qjax83: Win.Trojan.B-468 FOUND"
Log(GetLink(Text))


Sub GetLink(Text As String) As String
    Dim StartPos, EndPos As Int
    StartPos = Text.LastIndexOf("/") + 1
    EndPos = Text.IndexOf(":")
    Return Text.SubString2(StartPos, EndPos)
End Sub
Thanks for the example, if it is 1 line it can be done but for multiple lines, it need a more complicated code to get for each line. Am I missing stg ?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Oh, in your first post is it a single string?

If so:
B4X:
Dim Text As String = _
$"/var/www/xx.yy.com/public_html/files/qjax83: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/chyusc: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/7tyskq: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/bpjeu5: Win.Trojan.MSShellcode-7 FOUND
/var/www/xx.yy.com/public_html/files/q766jv: Win.Trojan.MSShellcode-7 FOUND
/var/www/xx.yy.com/public_html/files/lhie42: Doc.Malware.Valyria-6728957-0 FOUND
"$  

Dim lstTexts As List = Regex.Split("/var", Text)
For Each Txt As String In lstTexts
    If Txt.Length > 0 Then
        Log(GetLink(Txt))
    End If
Next
B4X:
Sub GetLink(Text As String) As String
    Return Text.SubString2(Text.LastIndexOf("/") + 1, Text.IndexOf(":"))
End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
B4X:
    Dim m As Matcher
    Dim mylines As String=$"/var/www/xx.yy.com/public_html/files/qjax83: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/chyusc: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/7tyskq: Win.Trojan.B-468 FOUND
/var/www/xx.yy.com/public_html/files/bpjeu5: Win.Trojan.MSShellcode-7 FOUND
/var/www/xx.yy.com/public_html/files/q766jv: Win.Trojan.MSShellcode-7 FOUND
/var/www/xx.yy.com/public_html/files/lhie42: Doc.Malware.Valyria-6728957-0 FOUND"$
    
    m=Regex.Matcher("/(\w+):",mylines)
    Do While m.Find
        Log(m.Group(1))
    Loop
 
Upvote 0
Top