Jump to content
Sign in to follow this  
Damein

StringRegExp.. again..

Recommended Posts

Damein

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.

MCR.jpg?t=1286371579

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

Share this post


Link to post
Share on other sites
jdelaney

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 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.

Share this post


Link to post
Share on other sites
Damein

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 by Damein

MCR.jpg?t=1286371579

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

Share this post


Link to post
Share on other sites
mikell

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 by mikell

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×