AutoHotkey Community

It is currently May 27th, 2012, 12:22 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: December 1st, 2008, 10:30 pm 
Offline

Joined: February 5th, 2007, 3:37 pm
Posts: 31
Hi,

I'm using RegExMatch to retrieve different things in a string (works great)

For instance will this code:
Code:
RegExMatch(players, "(?<=gq_name</td><td>).*?(?=</td>)",nicks)
give me first instance in below code example which is "REGGAE"

But how can I retrive all nicks (gq_name) from below string to an array with line break after each nick ?

Code:
<table><thead style="font-weight:bold"><tr><td>key</td><td>value</td></tr></thead><tbody><tr><td>frags</td><td>15</td></tr><tr><td>ping</td><td>226</td></tr><tr><td>nick</td><td>REGGAE</td></tr><tr><td>gq_name</td><td>REGGAE</td></tr><tr><td>gq_score</td><td>15</td></tr><tr><td>gq_ping</td><td>226</td></tr></tbody></table><table><thead style="font-weight:bold"><tr><td>key</td><td>value</td></tr></thead><tbody><tr><td>frags</td><td>0</td></tr><tr><td>ping</td><td>204</td></tr><tr><td>nick</td><td>combat</td></tr><tr><td>gq_name</td><td>combat</td></tr><tr><td>gq_score</td><td>0</td></tr><tr><td>gq_ping</td><td>204</td></tr></tbody></table><table><thead style="font-weight:bold"><tr><td>key</td><td>value</td></tr></thead><tbody><tr><td>frags</td><td>0</td></tr><tr><td>ping</td><td>147</td></tr><tr><td>nick</td><td>^3[=A^4-K=^1]U2</td></tr><tr><td>gq_name</td><td>^3[=A^4-K=^1]U2</td></tr><tr><td>gq_score</td><td>0</td></tr><tr><td>gq_ping</td><td>147</td></tr></tbody></table>


I appreciate any help & hints.
Thanks in advance :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2008, 1:30 am 
Offline

Joined: July 18th, 2006, 12:18 pm
Posts: 403
before i even attempt to look at your regex, Im gona ask you something.

You do no regexmatch returns an array of variables right?

meaning nicks1 will contain first result.
nicks2 will contain second etc..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2008, 5:34 am 
Offline

Joined: May 28th, 2008, 2:11 am
Posts: 739
Location: Minnesota, USA
Code:
x = ; HTML String here
StartingPos := 1
Loop {
   If (!StartingPos := RegExMatch(x, "(?<=gq_name</td><td>).*?(?=</td>)",nicks,StartingPos + 1))
      Break
   MsgBox % nicks%A_Index% := nicks
   nicks0 := A_Index
}
MsgBox % nicks0 . " names found"

_________________
Unless otherwise stated, all code is untested

(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2008, 8:58 am 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
Hi,

You can try this:
Code:

Haystack = ; HTML String here

RegExMatch(Haystack,"i)^.*gq_name</td><td>(.*?)</td>.*gq_name</td><td>(.*?)</td>.*gq_name</td><td>(.*?)</td>", Needle)

Msgbox, %Needle1%`n%Needle2%`n%Needle3%


Hope this example and the above one helps you.

Twhyman.

_________________
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2008, 8:55 pm 
Offline

Joined: February 5th, 2007, 3:37 pm
Posts: 31
What makes AHK so great is the people who wants to help!

I didn't mention that there could be up to 60 needles. That would be an enourmous RegEx I guess.
So I go with Slanters suggestion :D

Many thanks to both of you :mrgreen:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, Exabot [Bot], jrav and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group