Why RegEx does not search ?

peacemaker

Expert
Licensed User
Longtime User
c&&(_c.className+=_n);_s&&(_s.className+=_n);}catch(e){}})();</script><div class="mw"><div id="sfcnt" style="display:none"><div id="sform" style="height:36px"></div><div class="tsf-p" style="visibility:hidden"><span style="float:left"></span></div></div><div id="srchdsc"></div><div id="sdb"> </div><div id="subform_ctrl" style="display:none"></div></div><div id="appbar"><div style="border-bottom:1px solid #dedede;height:57px"><div id="ab_name"><span id="ab_label"><span>Search</span></span></div> <div style="position:relative"> <div><div id=resultStats>About 2,520,000,000 results<nobr> (0.24 seconds)&nbsp;</nobr></div></div> </div> <ol id="ab_ctls"><li class="ab_ctl" id="ab_ctl_ps"><a class="ab_button left kbtn-small selected" href="https://www.google.com/search?rlz=1C1AVSX_enRU416RU416&amp;ie=UTF-8&amp;q=google+

RegExr shows that "About 2,520,000,000 results<nobr> (0.13 seconds)" is matched if
B4X:
RegExp: /About.*results.*seconds/gi
pattern: About.*results.*seconds
flags: gi

but not found in

B4X:
Dim m As Matcher
Pattern = "About.*results.*seconds"
m = Regex.Matcher(Pattern, tr)
Do While m.Find
  a = m.GetStart(0) + 5
  tr = m.Match
Loop

Why ?
 

NJDude

Expert
Licensed User
Longtime User
This code works:
B4X:
Dim text, pattern As String

text = "c&&(_c.className+=_n);_s&&(_s.className+=_n);}catc h(e){}})();</script><div class='mw'><div id='sfcnt' style='display:none'><div id='sform' style='height:36px'></div><div class='tsf-p' style='visibility:hidden'><span style='float:left'></span></div></div><div id='srchdsc'></div><div id='sdb'> </div><div id='subform_ctrl' style='display:none'></div></div><div id='appbar'><div style='border-bottom:1px solid #dedede;height:57px'><div id='ab_name'><span id='ab_label'><span>Search</span></span></div> <div style='position:relative'> <div><div id=resultStats>About 2,520,000,000 results<nobr> (0.24 seconds)&nbsp;</nobr></div></div> </div> <ol id='ab_ctls'><li class='ab_ctl' id='ab_ctl_ps'><a class='ab_button left kbtn-small selected' href='https://www.google.com/search?rlz=1C1AVSX_enRU416RU416&amp;ie=UTF-8&amp;q=google+ "

pattern =  "About.*results.*seconds."

Dim Matcher1 As Matcher

Matcher1 = Regex.Matcher(pattern, text)

Do While Matcher1.Find

    Msgbox("Found: " & Matcher1.Match, "")

Loop

By the way, I replaced all the " for ' in the text to search so this sample could work, I'm assuming you are reading from an HTML so no need to do that.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Yes, text is got by HttpUtils.
UPD: solved - the HTML text was not so as suspected.
 
Last edited:
Upvote 0
Top