Android Question Regex quick question

pluton

Active Member
Licensed User
Longtime User
I have all dax trying to "regex" some strings

I need to pull out text between two one class.

When I go on this web: Regex and there enter my string is showing in result but in the app I can't get the text.

My regex expression is this:
B4X:
<div class="some-text-i-need-in-this-class">.*<div class="some-other-class">

Am I missing some expression or I'm doing wrong regex
 

Theera

Expert
Licensed User
Longtime User
It's a like this example.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim s As String = "<img align=""left"" alt=""blabla"" class=""ngg-singlepic ngg-left"" height=""180"" src=""http://www.mysite.it/wp-content/gallery/presentazione/logo_mercato_2012-13.jpg"" width=""300"" />"
    Dim m As Matcher = Regex.Matcher("<img [^>]+ src=\""([^""]+)""", s)
    If m.Find Then
        Log(m.Group(1))
    End If
End Sub
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
It is like this.

Text i got is from web page and has many classes in it but I want to take text which is in one specific class. Let's call it MYCLASS :)

Structure look like this (see picture below)

class.png


My code is like this:

B4X:
text = TextReader1.ReadAll 'read web page

infpattern =  "<div class=" &QUOTE& "MYCLASS" &QUOTE& ".*<div class=" &QUOTE& "class6" &QUOTE& "></div>"

Dim Matcher1 As Matcher
Matcher1 = Regex.Matcher(infpattern, text)
Do While Matcher1.Find
Log(Matcher1.Match) 'just to check what has been matched
    ProgressDialogHide
    'some code when text matchs
    '...
Loop
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Alternatively you cam simply use indexOf (for the <div class='whatever'>), indexOf2(for the closing </div>) and then get the string needed using substring2.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Hi Mc73 I was thinking about it but somehow regex is I think better
Now I'm on work but later I will try Erel solution

BTW
It need tapatalk solution for this forum. I'm writing this with sony xperia and it writes me letters so slow
 
Upvote 0
Top