Damein Posted September 4, 2014 Share Posted September 4, 2014 For some reason I cannot understand this function, ever.. when I think I have it understand it I realize I don't. All I want to do is capture the number after the #. I think I have the expression correct but it doesn't seem to work. Thanks and sorry for another one of these! Global $PostCount, $String, $Count $String = '<span class="post-num">#1</span><span class="post-num">#2</span><span class="post-num">#3</span>' $Count = StringRegExp($String, '(?i)(?s)<span class="post-num">#(.*?)</span>',1) MsgBox(0, "Test", $Count[0]) ; What to put for the MsgBox? 0 shows a 1 (Means it found it) but anything higher causes an error. Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
jdelaney Posted September 4, 2014 Share Posted September 4, 2014 (edited) close: $String = '<span class="post-num">#1</span><span class="post-num">#2</span><span class="post-num">#3</span>' $Count = StringRegExp($String, '(?i)(?s)<span class="post-num">#(.*?)</span>',3) For $i = 0 To UBound($Count)-1 MsgBox(1,1,$Count[$i]) Next or, view the array directly for debugging: #include <Array.au3> Global $PostCount, $String, $Count $String = '<span class="post-num">#1</span><span class="post-num">#2</span><span class="post-num">#3</span>' $Count = StringRegExp($String, '(?i)(?s)<span class="post-num">#(.*?)</span>',3) _ArrayDisplay($Count) If you really just want the count of matches: Global $PostCount, $String, $Count $String = '<span class="post-num">#1</span><span class="post-num">#2</span><span class="post-num">#3</span>' $array = StringRegExp($String, '(?i)(?s)<span class="post-num">#(.*?)</span>',3) $count = UBound($array) ConsoleWrite("Matches=" & $count & @CRLF) Edited September 4, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Damein Posted September 7, 2014 Author Share Posted September 7, 2014 (edited) Thank you for the help was most helpful! But I have another issue. I wan't to use a variable inside a StringRegExp but cannot figure out the correct format for it. StringRegExp($sSource, '(?i)(?s)' & $Info[6][1] & '(.*?)' & $Info[7][1] & ', 3) Is what I am attempting. Edited September 7, 2014 by Damein Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
mikell Posted September 7, 2014 Share Posted September 7, 2014 (edited) Using previous sample : #include <Array.au3> $String = '<span class="post-num">#15</span><span class="post-num">#26</span><span class="post-num">#37</span>' $var = "#" $start = '<span class="post-num">' $end = "</span>" $Count = StringRegExp($String, '(?is)' & $start & $var & '(.*?)' & $end, 3) _ArrayDisplay($Count) Edit But you will need to be very careful with the content of the vars : if there are special characters, use Q...E #include <Array.au3> $String = '<span class="post-num">$15</span><span class="post-num">$26</span><span class="post-num">$37</span>' $var = "$" $array = StringRegExp($String, '(?is)<span class="post-num">\Q' & $var & '\E(.*?)</span>',3) _ArrayDisplay($array) Edited September 7, 2014 by mikell Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now