mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 3 1 2 3
#231572 24/04/11 02:28 PM
Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
I have a script that uses sockets. But I always have the same trouble. Example, a piece of a html code:
<span class="title">Just A random text</span>
How can I get the piece of text by using regex or something else?

Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
try...
Code:
/noop $regex(title,%string,/<span class="title">(.+)<\/span>/ig)

...and then using...
Code:
$regml(title,N)

...to retrieve the title, where N is 1, 2, 3, etc. for the first match, second match, etc.

Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
It works smile

Another question:
I need a timer to sockclose my socket, because otherwise it's closed before the information is received. But if I use:
Code:
/timer 1 1 /sockclose [name]

there wil be like 700 timers of closing the socket. Can someone help me with this problem.

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Edit: I'm not sure why 5618 used "title" and the /g modifier when they aren't really needed.

Last edited by Tomao; 24/04/11 06:25 PM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: LMN
Another question:
I need a timer to sockclose my socket, because otherwise it's closed before the information is received. But if I use:
Code:
/timer 1 1 /sockclose [name]

there wil be like 700 timers of closing the socket. Can someone help me with this problem.
under your socketopen event, add
Code:
sockwrite -nt $sockname Connection: close
under your "Host:" this will prompt the connection to be closed after the info is received.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
As long as you put a /sockclose command at the very end of your socket script and not anywhere else, it should not close before you're done.

There are also $htmlfree identifiers floating around (including on this forum), where it will strip all of the html tags from text rather than using different ones for different tags.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
You need to make your regex ungreedy by changing ".+" to ".+?" like this:

Code:
//noop $regex(title,%string,/<span class="title">(.+?)<\/span>/ig)


You can see the difference between the two by typing these two commands:

Code:
//var %string = <span class="title">abc</span><span class="anotherspan">def</span> | noop $regex(title,%string,/<span class="title">(.+?)<\/span>/ig) | echo -a $regml(title,1)
//var %string = <span class="title">abc</span><span class="anotherspan">def</span> | noop $regex(title,%string,/<span class="title">(.+)<\/span>/ig) | echo -a $regml(title,1)


Mine (ungreedy): abc
Yours (greedy): abc</span><span class="anotherspan">def

A greedy regex matches as much data as it possibly can, while an ungreedy regex matches as little data as it possibly can. This is why yours matches up to the final </span> and mine only matches up to the first </span> smile

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
hixxy, if you already make it un-greedy, why do you keep the /g modifier? I believe you can use the /U modifier as well:
Code:
/<span class="title">(.+)<\/span>/iU

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I left /g in there so that it will support multiple span tags on one line, but you would need to loop through $regml(title,N)

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
To clarify, there are two different "greedy" at work here. Yours, Tomao, would be greedy in that it would take everything until the final matching text. So, as hixxy mentioned, you would capture everything to the last </span>. If you only have one on a line, that's not going to hurt anything, but if there are multiple </span> on a line, you will get unwanted data. You also won't be able to get $regml(2) because there will only every be one match.

With hixxy's, the greedy means to accept multiple matches. The match only goes to the first </span>. Then, the next match, if there is one, will go to the next one and so on. So you can then use $regml(N) to get multiple matches if there is more than one on the line.

One other note... /g really shouldn't ever be needed in this specific case. Normally, there should never be more than one <title> tag on a page. But it's a good thing to understand because it is very useful for other situations.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 3,971
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,971
You're not clarifying anything, rather the opposite.
There are not two different 'greedy' here, greedy has only one meaning:
Quote:
A greedy regex matches as much data as it possibly can, while an ungreedy regex matches as little data as it possibly can.
that's all.

Tomao: /g has nothing to do with greedy and /U only makes the whole expression ungreedy by default, where .+? would now represent a greedy search


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Although "greedy" is probably a better word to describe the behaviour of the /g modifier in regex, it actually means "global" - this is probably so as not to confuse it with greedy matching.

We're not matching <title>, we're matching a span tag with the class name of title: <span class="title"></span> and, as far as I know, you can have as many of those as you want on a page and it will still be valid HTML. Correct me if I'm wrong smile

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
@Wims: Ok, /g is global. I've heard it called greedy from enough people that I thought that was the correct name for it. Anyhow, take out the "greedy" from my previous post and it still explains the difference between the two things. There are two "things" going on rather than two kinds of "greedy".

@hixxy: You're right. I was thinking <title> rather than <span...>. It's been a long time since I've done much with HTML and most of that was before <span> was used very much. So I forgot how it was being used. Oops. blush

I don't think a well written site is likely to have more than one on a single line, though. There may be some valid reasons for it, but normally I don't think it would be necessary. Anyhow, /g isn't going to hurt anything whether it is needed or not. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
There are in total 8 matches. But instead of that $regml(title,2) and $regml(title,3) etc. show the second and third match etc., I just get 8 times a new $regml(title,1)
I am now using the
Code:
//noop $regex(title,%string,/<span class="title">(.+?)<\/span>/ig)
code.
Can anyone help me by getting the second match as $regml(2) and the third match as $regml(3) etc. instead of 8 times a different $regml(1)?

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
That works fine for what it is meant to do. If you have the following as the %string-

Code:
<span class="title">text1</span><span class="title">text2</span><span class="title">text3</span>


And then use that $regex, then:

$regml(title,1) = text1
$regml(title,2) = text2
$regml(title,3) = text3

If you give us your %sting that has 8 matches in it, we can tell you if there's an issue.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
It's in Dutch, so you won't understand much of the text:
Code:
 /noop $regex(FCKnudde,%sockreader,/<span class="title">(.+?)<\/span>/ig) | if ($regml(FCKnudde,1) != $null) { /echo -a regml 1: $regml(FCKnudde,1) $+ , regml 2: $regml(FCKnudde2,2) $+ , regml 3: $regml(FCKnudde,3) $+ , regml 4: $regml(FCKnudde,4)

Results in:
Code:
regml 1: Ferguson lyrisch over Neuer, regml 2: , regml 3: , regml 4:
regml 1: Ajax laat Dost vallen en wil Matavz, regml 2: , regml 3: , regml 4:
regml 1: Bayern wordt steeds gezelliger, regml 2: , regml 3: , regml 4:
regml 1: Real Madrid verslaat Barcelona, regml 2: , regml 3: , regml 4:
regml 1: Van der Wiel voor 10 miljoen naar Bayern, regml 2: , regml 3: , regml 4:
regml 1: Van den Boog: Gaat verdomme goed met Ajax!, regml 2: , regml 3: , regml 4:
regml 1: Magische aanpak Andries Jonker werkt, regml 2: , regml 3: , regml 4:
regml 1: AZ jat 4e plek van ADO, regml 2: , regml 3: , regml 4:

Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
That's probably because there are (at least) 8 /sockreads, all of which are run through /noop $regex() separately.
So this has nothing to do with $regml() but rather with the number of (and appearance of <span class="title">...<\/span> in) /sockread until the receive buffer is empty.

Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
But can I change that or is that impossible?

Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Of course it can be changed. But what *do* you want the script to show? And you'll need to post the entire script.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
In addition to your answers to 5618, $regml(title,N) where N is a number will only populate if everything is in a single variable/line. If they are all on separate lines (separate /sockreads), then there is only ever 1 match each time $regex() is called. That means $regml(title,2) and up will be $null.

If you want them all on one line (which may end making the line too long to display), then you'd want to set a variable and add to it...

sockread #1 sets variable to $regml(title,1)
sockread #2 sets variable to variable, $regml(title,2)
etc.

In the end, you have a variable with all of the titles listed.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
Code:
alias FCKnudde {
  /sockclose FCKnudde
  /sockopen FCKnudde www.nusport.nl 80 
} 

on *:SOCKOPEN:FCKnudde: {
  sockwrite -nt $sockname GET /fc-knudde/ HTTP/2.0
  sockwrite -nt $sockname Host: www.nusport.nl
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname $crlf
}

on *:SOCKREAD:FCKnudde: {
  if ($sockerr) { echo -a SOCKERR: $sockerr | halt }
  else {
    var %sockreader
    sockread -f %sockreader
    /noop $regex(FCKnudde,%sockreader,/<span class="title">(.+?)<\/span>/ig) | if ($regml(FCKnudde,1) != $null) { /echo -a regml 1: $regml(FCKnudde,1) $+ , regml 2: $regml(FCKnudde2,2) $+ , regml 3: $regml(FCKnudde,3) $+ , regml 4: $regml(FCKnudde,4) }
  }
}

It shows:
Code:
regml 1: Ferguson lyrisch over Neuer, regml 2: , regml 3: , regml 4:
regml 1: Ajax laat Dost vallen en wil Matavz, regml 2: , regml 3: , regml 4:
regml 1: Bayern wordt steeds gezelliger, regml 2: , regml 3: , regml 4:
regml 1: Real Madrid verslaat Barcelona, regml 2: , regml 3: , regml 4:
regml 1: Van der Wiel voor 10 miljoen naar Bayern, regml 2: , regml 3: , regml 4:
regml 1: Van den Boog: Gaat verdomme goed met Ajax!, regml 2: , regml 3: , regml 4:
regml 1: Magische aanpak Andries Jonker werkt, regml 2: , regml 3: , regml 4:
regml 1: AZ jat 4e plek van ADO, regml 2: , regml 3: , regml 4:

I want to get every sentence in a variable, so it's handy if I can get it like this:
Code:
regml 1: Ferguson lyrisch over Neuer, regml 2: Ajax laat Dost vallen en wil Matavz, regml 3: Bayern wordt steeds gezelliger, regml 4: Real Madrid verslaat Barcelona, etc.


Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
Originally Posted By: Riamus2
In addition to your answers to 5618, $regml(title,N) where N is a number will only populate if everything is in a single variable/line. If they are all on separate lines (separate /sockreads), then there is only ever 1 match each time $regex() is called. That means $regml(title,2) and up will be $null.

If you want them all on one line (which may end making the line too long to display), then you'd want to set a variable and add to it...

sockread #1 sets variable to $regml(title,1)
sockread #2 sets variable to variable, $regml(title,2)
etc.

In the end, you have a variable with all of the titles listed.

Where should I add it?

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Please delete. Double posted by accident.

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: LMN
I want to get every sentence in a variable, so it's handy if I can get it like this:
regml 1: Ferguson lyrisch over Neuer, regml 2: Ajax laat Dost vallen en wil Matavz, regml 3: Bayern wordt steeds gezelliger, regml 4: Real Madrid verslaat Barcelona, etc.
The code below will do exactly as you've described:
Code:
alias FCKnudde {
  sockclose FCKnudde
  sockopen FCKnudde www.nusport.nl 80 
} 
on *:SOCKCLOSE:FCKnudde: {
  var %x, %. 1
  while (%. <= $numtok(%sockreader,160)) {
    %x = %x $+(regml,$chr(32),%.,:,$chr(32),$+($,%.))
    inc %.
  }
  tokenize 160 %sockreader
  echo -a $left([ [ %x ] ],-1)
  unset %sockreader
}
on *:SOCKOPEN:FCKnudde: {
  sockwrite -nt $sockname GET /fc-knudde/ HTTP/2.0
  sockwrite -nt $sockname Host: www.nusport.nl
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname
}
on *:SOCKREAD:FCKnudde: {
  if ($sockerr) { echo -a SOCKERR: $sockerr | halt }
  else {
    sockread -fn &sockreader
    if ($regex($bvar(&sockreader,1-).text,/<span class="title">(.+?)<\/span>/i)) {
      set %sockreader $addtok(%sockreader,$+($regml(1),$chr(44),$chr(32)),160)
    }
  }
}

Last edited by Tomao; 27/04/11 06:26 PM.
Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
Edit: Because of a mistake of myself it didn't work, now it does.
But with this script I can't put the sentences in variables myself. Can someone help me with that?

Last edited by LMN; 28/04/11 04:51 PM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Quote:
Because of a mistake of myself it didn't work, now it does.
What mistake did you make?
Quote:
I can't put the sentences in variables myself
What do you mean by that? The socket script you've shown above is to grab the info from a website and fill the variable or binary variable under sockread as a buffer.

Have you tried the example I provided?

Last edited by Tomao; 28/04/11 05:12 PM.
Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
The mistake doesn't matter, it was with having 2 scripts that work with the trigger /fcknudde, so that's why it went wrong. I used your script, it echoes:
Code:
regml 1: Echte voetbal zegeviert, regml 2: Ferguson lyrisch over Neuer, regml 3: Ajax laat Dost vallen en wil Matavz, regml 4: Bayern wordt steeds gezelliger, regml 5: Real Madrid verslaat Barcelona, regml 6: Van der Wiel voor 10 miljoen naar Bayern, regml 7: Van den Boog: Gaat verdomme goed met Ajax!, regml 8: Magische aanpak Andries Jonker werkt

But now I want every sentence in a different variable. So that this is standing in my variable list:
Code:
Let's call the variables like this:
%fcknudde1 Echte voetbal zegeviert
%fcknudde2 Ferguson lyrisch over Neuer
%fcknudde3 Ajax laat Dost vallen en wil Matavz
etc.

Can you help me with that?

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If you had said you wanted it in separate variables to begin with rather than all in one, it would have been faster to get you want you wanted.

Code:
alias FCKnudde {
  sockclose FCKnudde
  unset %fcknudde.*
  sockopen FCKnudde www.nusport.nl 80 
} 
on *:SOCKOPEN:FCKnudde: {
  sockwrite -nt $sockname GET /fc-knudde/ HTTP/2.0
  sockwrite -nt $sockname Host: www.nusport.nl
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname
}
on *:SOCKREAD:FCKnudde: {
  if ($sockerr) { echo -a SOCKERR: $sockerr | halt }
  else {
    sockread -fn &sockreader
    if ($regex($bvar(&sockreader,1-).text,/<span class="title">(.+?)<\/span>/i)) {
      inc %fcknudde.cnt
      set %fcknudde. $+ %fcknudde.cnt $regml(1)
    }
  }
}



** Not really sure why we're using HTTP 2.0 here. Typically, it's 1.0 or sometimes 1.1. But as long as it's working, it should be fine.

Last edited by Riamus2; 28/04/11 07:11 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
There is only 1 variable:
Code:
%fcknudde. Magische aanpak Andries Jonker werkt

Fixed it myself:
Code:
inc %fcknudde.cnt
should have been
Code:
%c

Thank all of you for your time and effort. I've learnt more of Regular expressions and some other things and my script is ready to be used. Thank you!

Last edited by LMN; 28/04/11 05:55 PM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Riamus2, your edit shows the variables like this:
Quote:
%fcknudde.cnt 8
%fcknudde. Magische aanpak Andries Jonker werkt
This, I reckon, is what LMN wants:
Code:
alias FCKnudde {
  sockclose FCKnudde
  sockopen FCKnudde www.nusport.nl 80 
} 
on *:SOCKCLOSE:FCKnudde: {
  var %x, %. 1
  while (%. <= $numtok(%sockreader,160)) {
    set $+(%,fcknudde,%.) $gettok(%sockreader,%.,160)
    inc %.
  }
  unset %sockreader
}
on *:SOCKOPEN:FCKnudde: {
  sockwrite -nt $sockname GET /fc-knudde/ HTTP/2.0
  sockwrite -nt $sockname Host: www.nusport.nl
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname
}
on *:SOCKREAD:FCKnudde: {
  if ($sockerr) { echo -a SOCKERR: $sockerr | halt }
  else {
    sockread -fn &sockreader
    if ($regex($bvar(&sockreader,1-).text,/<span class="title">(.+?)<\/span>/i)) {
      set %sockreader $addtok(%sockreader,$regml(1),160)
    }
  }
}
Quote:
%fcknudde1 Echte voetbal zegeviert
%fcknudde2 Ferguson lyrisch over Neuer
%fcknudde3 Ajax laat Dost vallen en wil Matavz
%fcknudde4 Bayern wordt steeds gezelliger
%fcknudde5 Real Madrid verslaat Barcelona
%fcknudde6 Van der Wiel voor 10 miljoen naar Bayern
%fcknudde7 Van den Boog: Gaat verdomme goed met Ajax!
%fcknudde8 Magische aanpak Andries Jonker werkt

Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
Originally Posted By: Tomao
Riamus2, your edit shows the variables like this:
Quote:
%fcknudde.cnt 8
%fcknudde. Magische aanpak Andries Jonker werkt
This, I reckon, is what LMN wants:
Code:
alias FCKnudde {
  sockclose FCKnudde
  sockopen FCKnudde www.nusport.nl 80 
} 
on *:SOCKCLOSE:FCKnudde: {
  var %x, %. 1
  while (%. <= $numtok(%sockreader,160)) {
    set $+(%,fcknudde,%.) $gettok(%sockreader,%.,160)
    inc %.
  }
  unset %sockreader
}
on *:SOCKOPEN:FCKnudde: {
  sockwrite -nt $sockname GET /fc-knudde/ HTTP/2.0
  sockwrite -nt $sockname Host: www.nusport.nl
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname
}
on *:SOCKREAD:FCKnudde: {
  if ($sockerr) { echo -a SOCKERR: $sockerr | halt }
  else {
    sockread -fn &sockreader
    if ($regex($bvar(&sockreader,1-).text,/<span class="title">(.+?)<\/span>/i)) {
      set %sockreader $addtok(%sockreader,$regml(1),160)
    }
  }
}
Quote:
%fcknudde1 Echte voetbal zegeviert
%fcknudde2 Ferguson lyrisch over Neuer
%fcknudde3 Ajax laat Dost vallen en wil Matavz
%fcknudde4 Bayern wordt steeds gezelliger
%fcknudde5 Real Madrid verslaat Barcelona
%fcknudde6 Van der Wiel voor 10 miljoen naar Bayern
%fcknudde7 Van den Boog: Gaat verdomme goed met Ajax!
%fcknudde8 Magische aanpak Andries Jonker werkt

It's already fixed. Thank you for your time smile

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Well you might want to add:
Code:
on *:SOCKCLOSE:FCKnudde: { unset %c }
So the %c var doesn't get left behind.

If left unset, it'll become like this after the second trigger:
Quote:
%c 16
%fcknudde.1 Echte voetbal zegeviert
%fcknudde.2 Ferguson lyrisch over Neuer
%fcknudde.3 Ajax laat Dost vallen en wil Matavz
%fcknudde.4 Bayern wordt steeds gezelliger
%fcknudde.5 Real Madrid verslaat Barcelona
%fcknudde.6 Van der Wiel voor 10 miljoen naar Bayern
%fcknudde.7 Van den Boog: Gaat verdomme goed met Ajax!
%fcknudde.8 Magische aanpak Andries Jonker werkt
%fcknudde.9 Echte voetbal zegeviert
%fcknudde.10 Ferguson lyrisch over Neuer
%fcknudde.11 Ajax laat Dost vallen en wil Matavz
%fcknudde.12 Bayern wordt steeds gezelliger
%fcknudde.13 Real Madrid verslaat Barcelona
%fcknudde.14 Van der Wiel voor 10 miljoen naar Bayern
%fcknudde.15 Van den Boog: Gaat verdomme goed met Ajax!
%fcknudde.16 Magische aanpak Andries Jonker werkt
And it just keeps incrementing to make your variables large.

Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
Maybe that's handy ^^

Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
One last question:
if I have:
Code:
<a href="#" onclick="NU.popup('/fc-knudde/1000709/popup.html','Cartoon','480','730'); return false;">

Hoe can I get the part:
Code:
/fc-knudde/1000709/popup.html

with a regex then? If I can get them by $regml then it's fine, then I can finish it myself now.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Actually, %c would be better as %fcknudde.cnt . I changed it to that on purpose, but ended up forgetting one of them. I'll edit the orginal to show.

Reasons to use that instead of %c-
1) Only a single unset is necessary (already included in what I posted above).
2) single characters or common names are usually a bad idea for global variables. %c is great for a local variable counter, but in this instance, you need a global variable and for that, %c is a bad idea. There is too much chance of conflicts with other scripts. And in case anyone doesn't know, /set is global and /var is local.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: LMN
One last question:
if I have:
Code:
<a href="#" onclick="NU.popup('/fc-knudde/1000709/popup.html','Cartoon','480','730'); return false;">

Hoe can I get the part:
Code:
/fc-knudde/1000709/popup.html

Code:
//tokenize 40 <a href="#" onclick="NU.popup('/fc-knudde/1000709/popup.html','Cartoon','480','730'); return false;"> | echo -a $gettok($2,1,39)
You don't have to engage regex in everything you code...

Joined: Mar 2011
Posts: 23
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Mar 2011
Posts: 23
Originally Posted By: LMN
One last question:
if I have:
Code:
<a href="#" onclick="NU.popup('/fc-knudde/1000709/popup.html','Cartoon','480','730'); return false;">

Hoe can I get the part:
Code:
/fc-knudde/1000709/popup.html

with a regex then? If I can get them by $regml then it's fine, then I can finish it myself now.


This would get it with regex. The \x28 is hex for the open parenthesis. Don't know why but Mirc gives an error if the open paren is simply escaped with a backslash as I normally would do.
Code:
var %subj = <a href="#" onclick="NU.popup('/fc-knudde/1000709/popup.html','Cartoon','480','730'); return false;">
noop $regex(%subj, /\x28'([^']+)/)
echo -s $regml(1)


Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
You can also use \50 in place of \x28

You're right about not being able to escape the parenthesis. I think mIRC mistakes it for its own bracing or something.

This also applies to mIRC's regex on text event, which doesn't have escape sequence. The only solution is using octal chrs.

Though most special characters can be treated literal when using the $regex() identifier.

Last edited by Tomao; 29/04/11 08:09 AM.
Joined: Mar 2011
Posts: 23
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Mar 2011
Posts: 23
Originally Posted By: Tomao
You can also use \50 in place of \x28


I prefer to use hex for literals as there is no ambiguity. If you want to use octals for literals, I would suggest to use \050 because \0 followed by two additional digits is always interpreted as a octal, whereas \50 is ambiguous and PCRE has to decide if its a backreference or an octal.

Originally Posted By: Tomao
You're right about not being able to escape the parenthesis. I think mIRC mistakes it for its own bracing or something.

This also applies to mIRC's regex on text event, which doesn't have escape sequence. The only solution is using octal chrs.

Though most special characters can be treated literal when using the $regex() identifier.


Actually if you put the pattern in a variable, the escaped open paren doesn't interfere with mirc's parsing.

Code:
  var %subj = <a href="#" onclick="NU.popup('/fc-knudde/1000709/popup.html','Cartoon','480','730'); return false;">
  var %pat = /\('([^']+)/
  noop $regex(%subj, %pat)
  echo -s $regml(1)



Joined: Jul 2006
Posts: 3,971
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,971
Yes, this is how mirc parse an identifier, every litteral ( ) must be balanced in their parameters or mirc will report an error


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Yes, I overlooked the feasibility of using a var.

The fact remains, the on text regex has no escape sequence, and we either need to use hex or octal to escape certain characters.

Joined: Jul 2006
Posts: 3,971
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,971
Quote:
the on text regex has no escape sequence, and we either need to use hex or octal to escape certain characters.
The bold part doesn't make sense confused (it's understood though) but that last statement is not true, the only thing we need to do is by passing the way mirc parses a code.
Using hex or octal to match a colon inside the matchtext of an event's definition because you used the $ prefix is one solution, but you could also not use the $ prefix and use $regex without any hex or octal, I just wanted to make that clear.

Last edited by Wims; 29/04/11 10:39 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Wims, what I was trying to say is this:

Quote:
on $*:text:/http:///Si:#:{
This will not match http:// It doesn't matter if you escape the colon character as \:

Quote:
on $*:text:/http\x3A///Si:#:{
By using \x3A, this regex will match http:// without a problem.

This does not apply to the use of $regex()

Last edited by Tomao; 30/04/11 12:44 AM.
Joined: Jul 2006
Posts: 3,971
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,971
I know what you were trying to say:
Quote:
The bold part doesn't make sense (it's understood though)
It's just that it's not about regex, you can't match a litteral colon inside the matchtext on an event, regex or not.
Your statement was then implying that octal or hex was the only solutions, as I said I just wanted to make it clear that it wasn't
Quote:
you could also not use the $ prefix and use $regex without any hex or octal, I just wanted to make that clear.

Note: you don't need to escape a colon in regex anyway

Last edited by Wims; 30/04/11 01:11 AM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Yes, I had the interpretation of "escape sequence" misunderstood and misconstrued. I learned that from this post initially, and I quote:

Why not escape it:
Code:

/^!foobar\:\S+/

Then you make the colon sign literal so it won't be associated with regex's special meaning.

Wiz126 replied:

This has nothing to do with regex, in fact he wants it to work with regex, not escape it. Like I said in my previous post its the way mIRC parses the event, also there is no escape sequences for match texts.

If you have something like: on $*:text:/^!foobar (?\:\S+)/:#:{

mIRC will parse is into "$*", "text", "/^!foobar (?\", "\S+)/", "?"
notice, at that point your matchtext is broken, this is done way before the matchtext is even being matched. as a result you simply cannot have colons in the matchtext at all.

Edited by Wiz126 (15/03/11 08:03 PM)

I really need to get with the program.

Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
But now I use:

Code:
/set %FCToken1 $gettok(%sockreader,1,40) | echo -a %FCToken1 | echo -a $gettok(%FCToken1,1,39)

It returns:
Code:
<span class="title">Knudde op vakantie</span><span class="cat">Maandag</span>
-
* /echo: insufficient parameters (line 22, script5.ini)
-
<span class="title">Robben: Bayern mist een echte leider</span><span class="cat">Vrijdag</span>
-
* /echo: insufficient parameters (line 22, script5.ini)
-
<span class="title">Echte voetbal zegeviert</span><span class="cat">Donderdag</span>
-
* /echo: insufficient parameters (line 22, script5.ini)
-
<span class="title">Ferguson lyrisch over Neuer</span><span class="cat">Woensdag</span>
-
* /echo: insufficient parameters (line 22, script5.ini)
-
<span class="title">Ajax laat Dost vallen en wil Matavz</span><span class="cat">Dinsdag</span>
-
* /echo: insufficient parameters (line 22, script5.ini)
-
<span class="title">Bayern wordt steeds gezelliger</span><span class="cat">Vrijdag</span>
-
* /echo: insufficient parameters (line 22, script5.ini)
-
<span class="title">Real Madrid verslaat Barcelona</span><span class="cat">Donderdag</span>
-
* /echo: insufficient parameters (line 22, script5.ini)
-
<span class="title">Van der Wiel voor 10 miljoen naar Bayern</span><span class="cat">Woensdag</span>
-
* /echo: insufficient parameters (line 22, script5.ini)

The /tokenize command didn't work. But this is not what I want, I want
Code:
/fc-knudde/1000709/popup.html
out of
Code:
<a href="#" onclick="NU.popup('/fc-knudde/1000709/popup.html','Cartoon','480','730'); return false;">

Joined: Jul 2006
Posts: 3,971
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,971
Quote:
But this is not what I want, I want

/fc-knudde/1000709/popup.html

out of

<a href="#" onclick="NU.popup('/fc-knudde/1000709/popup.html','Cartoon','480','730'); return false;">
$gettok(string,2,39)


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2010
Posts: 26
L
LMN Offline OP
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Dec 2010
Posts: 26
Oh, it's a bit dumb that I didn't think of that myself smile
Thank you all very much, I have my final script now.

Page 1 of 3 1 2 3

Link Copied to Clipboard