Sign in to follow this  
Followers 0
ChrisO

StringRegExp multiple returns

5 posts in this topic

Hey all,

I'm trying to parse a html page using StringRegExp to pull out some names that are useful to me. The portion of the html is:

<select name='list_ck[]' size="10" multiple="multiple" style='width:250px'>
<option value='jsmith'>John Smith</option><option value='esmith'>Eddie Smith</option>    </select>

The number of names can be any where from 0 to 4 and I need to grab each one. Here's what I have so far:

$regexpResults = StringRegExp($dlPOc,"list_ck[^<]+(?:<option\svalue='\w+'>([^<]+)</option>)*\s",3)

Am I over-complicating this? It seems like what I have should work but it only returns the last name (Eddie Smith) in this case.

Thanks in advance.

Share this post


Link to post
Share on other sites



Did you try looping through your array of results?

For $i=1 to Ubound($regexpResults)-1

msgbox(0,"",$regexpResults[$i])

Next

if that goesn't work try the flag 1 instad of flag 3?


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$html="<select name='list_ck[]' size=""10"" multiple=""multiple"" style='width:250px'>"&@CRLF& _
"<option value='jsmith'>John Smith</option><option value='esmith'>Eddie Smith</option>  </select>"
$array1=StringRegExp ($html, "(?s)(?i)<select name='list_ck(.+?)</select>",3)
    ; sets flag "(?s)", which means: "." matches any character including newline
    ; sets flag "(?i)", which means: case insensitive
If @error==1 Then ConsoleWrite("-> No matches for first RegExp!"&@CRLF)
_ArrayDisplay($array1)

; joins all the results in a single string:
$string=""
For $i=0 To UBound($array1)-1
    $string&=$array1[$i]
Next

$array2=StringRegExp ($string, "(?s)(?i)<option value='.+?'>(.+?)</option>",3)
If @error==1 Then ConsoleWrite("-> No matches for second RegExp!"&@CRLF)
_ArrayDisplay($array2)

EDIT: my browser is going nuts

Edited by footswitch

Share this post


Link to post
Share on other sites

Thanks both, as soon you pointed me towards using 2 passes with the regex, it became much simpler.

Problem solved ;)

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  
Followers 0