mIRC Home    About    Download    Register    News    Help

Print Thread
#132250 08/10/05 11:21 AM
Joined: Aug 2003
Posts: 80
H
HM2K Offline OP
Babel fish
OP Offline
Babel fish
H
Joined: Aug 2003
Posts: 80
I'm trying to figure out how to match and return IP addresses from a string of text, but can't seem to work it out.

This is what I came up with when playing with regex...

$regex(test test text text 123.123.123.123 string string,[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)

Which appears to return a 1.


-HM2K- hm2k.org
#132251 08/10/05 12:07 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
//echo -a $regex(This is a test server 123.123.143.123 Go check it out!,/((\d{1,3}\056){3}\d{1,3})/) $regml(1)
notethis asumes all the digits in the IP have a range of 0-255 266.266.266.266 would return 1 as well.

You can reference to what you enclose in ()'s with $regml later on, it returns 1 meaning it matched 1 times.


$maybe
#132252 08/10/05 12:49 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
/*

Usage: /catchips <string> or $catchips(<string>)

Example:

//echo -a $catchips(this is an ip 2.55.148.201 followed by a non ip 256.4.7.9)
-> 2.55.148.201

/catchips concatenated doesn't count255.12.5.8 and 5.5.5.5 or 6.6.6.6
-> 5.5.5.5 6.6.6.6

*/

Code:
alias catchips {
  !haltdef $regex(catchips,$1-,/(?&lt;=\s|^)((([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?3))(?=\s|$)/g)
  var %i = 1, %result
  while ($regml(catchips,%i)) { %result = %result $v1 | inc %i 3 }
  $iif($isid,return,echo -a) %result
}


Gone.
#132253 10/10/05 12:51 AM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Just showing another way to play with regex, hope you don't mind smile
Code:
alias catchips {
  var %r, %q = $regsub($1-,/\G.*?((?&lt;=\s|^)((?:([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?3))(?=\s|$))|\G(?!.*(?1)).*$/g, \1:, %r)
  $iif($isid,return,echo -a) $replace(%r,:,$chr(32))
}

#132254 10/10/05 01:34 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Of course I don't mind, I like variety in code smile


Gone.

Link Copied to Clipboard