mIRC Home    About    Download    Register    News    Help

Print Thread
#205348 20/10/08 06:55 PM
Joined: Mar 2007
Posts: 218
V
vexed2 Offline OP
Fjord artisan
OP Offline
Fjord artisan
V
Joined: Mar 2007
Posts: 218
I'm using the piece of code underneath to log and load urls, ftp links and such like into a simple dialog.
The problem i have just picked up on, It'll only log the first link, and not the rest if they are more on 1 line, would be greatful for a fix for this. Thanks.

Code:
on ^1:TEXT:*:?:{
  var %input = $strip($1-)
  var %url $regml($regex(%text,/((?:ftp:\/\/|https?:\/\/|www2?\.)[^<>\.\s]+(?:\.[^<>\.\s]+)+(?:\/[^<>\.\s]+)*)/g))
  if ($regml($regex(%text,/((?:ftp:\/\/|https?:\/\/|www2?\.)[^<>\.\s]+(?:\.[^<>\.\s]+)+(?:\/[^<>\.\s]+)*)/g))) {
    if ($read(system\url.txt,w,$regml(1)) == $null) { write system\url.txt $regml(1) }
    if ($dialog(url)) { loadbuf -ro url 1 system\url.txt }
    haltdef
  }
}

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Loop through $regml(0) to get all the matches


$maybe
Joined: Aug 2006
Posts: 3
A
Self-satisified door
Offline
Self-satisified door
A
Joined: Aug 2006
Posts: 3
What you're doing here, every time you pass $regex(%text,....) it is filling the $regml(n) with all the urls in the text.
$regex() it self will return the total number of matches, if this is 1, 2, 3 or 4 or what ever it may be, you'll do $regml(1) (or the total amount of matches)

What you need to do, is simple store the amount of matches to a variable and loop through all $regml(n) until you've been through the list.

Also worth a note you could make sure you're likely to want to try and capture the text inside your text event and use the 'strip' modifier as below.

Code:
on ^*:text:/ftp|http|www/iS:?: {
  var %i = $regex(%text,/((?:ftp:\/\/|https?:\/\/|www2?\.)[^<>\.\s]+(?:\.[^<>\.\s]+)+(?:\/[^<>\.\s]+)*)/giS)
  while (%i) {
    if ($read(system\url.txt,w,$regml(%i) == $null) write system\url.txt $regml(%i)
    dec %i
  }
  if ($dialog(url)) loadbuf -ro url 1 system\url.txt
}

Last edited by Albertrud; 21/10/08 03:34 PM.

--
Albie

Link Copied to Clipboard