Jump to content


Photo

DO...A_Index...work in RegExMatch( ) ?


  • Please log in to reply
11 replies to this topic

#1 leehong1

leehong1
  • Members
  • 373 posts

Posted 21 November 2011 - 07:29 AM

I have trouble working somthin like this.....
Loop, 5

{

RegExMatch( show, "s)<TD>(1)`r.<TD>[[color=red]A_Index[/color]]`r.<TD>(\d+)`r.<TD>(\d+)`r.<TD>(\d\.\d+)`r.<TD>(\d+/\d+)", m)



MsgBox, %m1%  %m2%  %m3%  %m4%  %m5%  %m6% 

}


#2 Guests

  • Guests

Posted 21 November 2011 - 07:59 AM

Loop, 5

{

RegExMatch( show, "s)<TD>(1)`r.<TD>[" A_Index "]`r.<TD>(\d+)`r.<TD>(\d+)`r.<TD>(\d\.\d+)`r.<TD>(\d+/\d+)", m)



MsgBox, %m1%  %m2%  %m3%  %m4%  %m5%  %m6%

}


#3 CodeKiller

CodeKiller
  • Members
  • 2066 posts

Posted 21 November 2011 - 09:13 AM

Explanation :
A_Index is a variable, so to use it in a string " " you must close the string.

txt1 := "content"
txt2 := "txt3"
txt3 := 1234
txt4 := "this is the " txt1 " of the var txt3 : " %txt2% "with reference"
msgbox % txt4


#4 leehong1

leehong1
  • Members
  • 373 posts

Posted 21 November 2011 - 09:43 AM

@ Guest, CodeKiller.....

thanks for helping....but this

[" A_Index "]

has to change to

(" A_Index ")

....now its running

#5 CodeKiller

CodeKiller
  • Members
  • 2066 posts

Posted 21 November 2011 - 02:32 PM

@ Guest, CodeKiller.....

thanks for helping....but this

[" A_Index "]

has to change to

(" A_Index ")

....now its running


The [ ] are special chars ([a-z], [0-9] for example), you must escape them before use :

"\[" A_Index " \]"



#6 leehong1

leehong1
  • Members
  • 373 posts

Posted 22 November 2011 - 03:34 AM

CodeKiller.....i tried

"\[" A_Index " \]"

i get this

---------------------------
data.ahk
---------------------------
Error at line 14.

Line Text: \["
Error: The leftmost character above is illegal in an expression.

The script was not reloaded; the old version will remain in effect.
---------------------------
OK
---------------------------

or this code do not work in AHK Basic

#7 lain

lain
  • Members
  • 186 posts

Posted 22 November 2011 - 08:28 AM

CodeKiller 's code is ok under ahk basic but it is hard to get the " positions right !!

data=mytest [12test]endoftest

loop 30
{
if regexmatch(data,"\[" A_Index "(t...)" "\]",result)
msgbox loopcount=%A_Index%  result=%result1%
}

exitapp


#8 leehong1

leehong1
  • Members
  • 373 posts

Posted 23 November 2011 - 03:03 AM

YUI....

what do i put in the (red )....

if regexmatch(data,"\[" A_Index "(t...)" "\]",result)


i need the second variable indexed...

RegExMatch( show, "s)<TD>(1)`r.<TD>(" A_Index ")`r.<TD>(\d+)`r.<TD>(\d+)`r.<TD>(\d\.\d+)`r.<TD>(\d+/\d+)", m) ;working code...



#9 lain

lain
  • Members
  • 186 posts

Posted 23 November 2011 - 09:08 AM

Can you give a real sample of the data you are using as "haystack"?

I am confused about the use of TD>(" A_Index ")`r.< while in the old it was

>[" A_Index "]`r.How does it look in the real code?

#10 leehong1

leehong1
  • Members
  • 373 posts

Posted 24 November 2011 - 04:31 AM

Yui.....
i have the code working in AHK BASIC with this....
RegExMatch( show, "s)<TD>(1)<\/TD>`r.<TD>(" A_Index ")<\/TD>`r.<TD>(\d+)<\/TD>`r.<TD>(\d+)<\/TD>`r.<TD>(\d\.\d+)<\/TD>`r.<TD>(\d+/\d+)<\/TD>", h1d)
This is a part of the (Haystack)Html....

<COLGROUP>

<COL width=20>

<COL style="FONT-WEIGHT: bold" width=20>

<COL width=51>

<COL width=51>

<COL width=31>

<COL class=limit width=auto></COLGROUP>

<TBODY>

<TR data-id="93010" data-type="Game">

<TD>1</TD>

<TD>1</TD>

<TD>23</TD>

<TD>21</TD>

<TD>44.5</TD>

<TD>77/35</TD></TR>

<TR data-id="923010" data-type="Game">

<TD>1</TD>

<TD>2</TD>

<TD>67</TD>

<TD>32</TD>

<TD>22.6</TD>

<TD>88/12</TD></TR>

<TR data-id="94110" data-type="Game">

<TD>1</TD>

<TD>3</TD>

<TD>3</TD>

<TD>4</TD>

<TD>74.7</TD>

<TD>96/3</TD></TR>

<TR data-id="963010" data-type="Game"



#11 lain

lain
  • Members
  • 186 posts

Posted 24 November 2011 - 08:32 AM

Thanks leehong1 for the haystack sample.I thought it contained a literal [ and in that case you need to escape it like CodeKiller suggested but that is not needed with (.

So the example i gave is not relevant to your problem anyway you solved it :)

#12 Gogo

Gogo
  • Guests

Posted 24 November 2011 - 11:17 AM

If you do not know how many the packets are you'd better use While-loop.
Data =
(
<COLGROUP>
<COL width=20>
<COL style="FONT-WEIGHT: bold" width=20>
<COL width=51>
<COL width=51>
<COL width=31>
<COL class=limit width=auto></COLGROUP>
<TBODY>
<TR data-id="93010" data-type="Game">
<TD>1</TD>
<TD>1</TD>
<TD>23</TD>
<TD>21</TD>
<TD>44.5</TD>
<TD>77/35</TD></TR>
<TR data-id="923010" data-type="Game">
<TD>1</TD>
<TD>2</TD>
<TD>67</TD>
<TD>32</TD>
<TD>22.6</TD>
<TD>88/12</TD></TR>
<TR data-id="94110" data-type="Game">
<TD>1</TD>
<TD>3</TD>
<TD>3</TD>
<TD>4</TD>
<TD>74.7</TD>
<TD>96/3</TD></TR>
<TR data-id="963010" data-type="Game">
)

Str:= RegExReplace(Data, "</TD>[^<]+<TD>", " ")  ; put a separator (space) between numbers
While RegExMatch(Str, "<TD>1 " A_Index " ([^<]+)", match)
  {
   MsgBox % A_index " --> " match1
  }