mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 3 1 2 3
Re: Regular expressions help? [Re: LMN] #231686 27/04/11 03:54 PM
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.


Re: Regular expressions help? [Re: Riamus2] #231687 27/04/11 03:56 PM
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?

Re: Regular expressions help? [Re: LMN] #231689 27/04/11 06:11 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Please delete. Double posted by accident.

Re: Regular expressions help? [Re: LMN] #231690 27/04/11 06:16 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
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.
Re: Regular expressions help? [Re: LMN] #231710 28/04/11 04:38 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.
Re: Regular expressions help? [Re: LMN] #231711 28/04/11 05:11 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
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.
Re: Regular expressions help? [Re: LMN] #231712 28/04/11 05:15 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?

Re: Regular expressions help? [Re: LMN] #231714 28/04/11 05:42 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
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
Re: Regular expressions help? [Re: LMN] #231715 28/04/11 05:51 PM
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.
Re: Regular expressions help? [Re: Riamus2] #231716 28/04/11 05:54 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
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

Re: Regular expressions help? [Re: Tomao] #231717 28/04/11 05:56 PM
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

Re: Regular expressions help? [Re: LMN] #231718 28/04/11 06:05 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
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.

Re: Regular expressions help? [Re: LMN] #231719 28/04/11 06:58 PM
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 ^^

Re: Regular expressions help? [Re: LMN] #231720 28/04/11 07:08 PM
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.

Re: Regular expressions help? [Re: LMN] #231721 28/04/11 07:10 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
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
Re: Regular expressions help? [Re: LMN] #231725 28/04/11 09:32 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
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...

Re: Regular expressions help? [Re: LMN] #231727 29/04/11 05:41 AM
Joined: Mar 2011
Posts: 23
S
Sherip Offline
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)


Re: Regular expressions help? [Re: Sherip] #231729 29/04/11 08:01 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
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.
Re: Regular expressions help? [Re: Tomao] #231735 29/04/11 12:31 PM
Joined: Mar 2011
Posts: 23
S
Sherip Offline
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)



Re: Regular expressions help? [Re: Sherip] #231736 29/04/11 02:43 PM
Joined: Jul 2006
Posts: 3,715
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,715
Yes, this is how mirc parse an identifier, every litteral ( ) must be balanced in their parameters or mirc will report an error


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Page 2 of 3 1 2 3