mIRC Home    About    Download    Register    News    Help

Print Thread
#249555 05/12/14 01:07 AM
Joined: Oct 2014
Posts: 7
W
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
W
Joined: Oct 2014
Posts: 7
How would I add to this so it would detect www aswell? - "I added full code"

Code:
on $*:TEXT:/(https?)\x3A\/\/(www\.)?([^\s\n\/]++)(\/\S*)?/Si:#:{
  ; Check if url contains skipped filetype
  var %skiptypes png jpg jpeg txt | var %filetype $gettok($regml(3),-1,46)
  if ($istok(%skiptypes,%filetype,32)) { halt }

  ; Start socket opening
  if ($sock(title)) { sockclose title }
  if ($regml(1) == http) { sockopen title $regml(2) 80 }
  if ($regml(1) == https) { sockopen -e title $regml(2) 443 }
  sockmark title $iif($regml(3),$v1,/) #
}
on *:SOCKOPEN:title:{
  if ($sockerr) {
    msg $gettok($sock(title).mark,2,32) Socket error: $sock(title).wsmsg
    halt
  }
  sockwrite -nt $sockname GET $iif($gettok($sock($sockname).mark,1,32),$v1,/) HTTP/1.0
  sockwrite -nt $sockname Host: $sock($sockname).addr
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:title:{
  var %titletag
  sockread %titletag
  if ($regex(titletag,%titletag,/<title>([^\n<]*+)/)) {
    msg $gettok($sock(title).mark,2,32) ^ $Xchr($left($regml(titletag,1),240))
    sockclose $sockname
  }
}

alias -l Xchr { 
  var %return $regsubex($regsubex($1-,/&#x([A-F0-9]{1,2});/g,$chr($base($regml(\n),16,10))),/&#([0-9]{2});/g,$chr(\1)) 
  return $replacecs(%return,&ndash;,&#150;,&middot;,·,&raquo;,»,&laquo;,«,&Uuml;,Ü,&uuml;,ü,&Aacute;,Á,&aacute;,á,&Eacute;,$&
    É,&eacute;,é,&Iacute;,Í,&iacute;,í,&Oacute;,Ó,&oacute;,ó,&Ntilde;,Ñ,&ntilde;,ñ,&Uacute;,Ú,&uacute;,ú,&nbsp;,$chr(32),$&
    &aelig;,æ,&quot;,",&amp;,&)
}

Last edited by WikkedGamer; 05/12/14 03:45 AM.
Joined: Jul 2006
Posts: 4,185
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,185
/(https?)\x3A\/\/(www\.)?([^\s\n\/]++)(\/\S*)?/Si

should work


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #249558 05/12/14 03:41 AM
Joined: Oct 2014
Posts: 7
W
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
W
Joined: Oct 2014
Posts: 7
doesn't work

Last edited by WikkedGamer; 05/12/14 03:43 AM.
Joined: Jul 2006
Posts: 4,185
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,185
It does work, it's just that I added one more capturing parenthesis (), which means that when www is used, the third capturing group should be the fourth.
To avoid this, you can use ?: to simply not make it a capturing group, but the semi colon ':' will make it fail because mirc seperate argument according to that semi colon, you can use an alias and $() to dynamically evaluate to avoid this issue:

Code:
alias my_url_pattern return /(https?)\x3A\/\/(?:www\.)?([^\s\n\/]++)(\/\S*)?/Si

on $*:TEXT:$($my_url_pattern):#:{
  ; Check if url contains skipped filetype
  var %skiptypes png jpg jpeg txt | var %filetype $gettok($regml(3),-1,46)
  if ($istok(%skiptypes,%filetype,32)) { halt }

  ; Start socket opening
  if ($sock(title)) { sockclose title }
  if ($regml(1) == http) { sockopen title $regml(2) 80 }
  if ($regml(1) == https) { sockopen -e title $regml(2) 443 }
  sockmark title $iif($regml(3),$v1,/) #
}
Try this


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #249572 05/12/14 12:27 PM
Joined: Jan 2004
Posts: 1,361
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,361
Your regex matches the same set of strings as the original, I think he wants to match www without http. I don't have time now.

Loki12583 #249575 05/12/14 02:53 PM
Joined: Jul 2006
Posts: 4,185
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,185
Not really but you have a point, didn't look at the pattern carefully, I assumed 'detect www' meant it wouldn't currently.

Code:
alias my_url_pattern return /(?:(https?)\x3A\/\/)?([^\s\n\/]++)(\/\S*)?/Si


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard