mIRC Homepage
Posted By: sparta $regex prob - 19/06/07 08:43 AM
How come i cant get this to react on unreal:// ? I have added it as hotlink, how ever the script dosent underline it as it should, do i miss something here?
Code:
alias urltheme {
  var %line = $1-
  if ($regex(%line,/(\b(www.?\.|https?:\/\/|ftp:\/\/|unreal://\/\/).)/i)) {
    var %x = 1
    while (%x <= $numtok(%line,32)) {
      if ($regex($gettok(%line,%x,32),/(\b(www.?\.|https?:\/\/|ftp:\/\/|unreal://\/\/).)/i)) {
        var %l2 = $+($clr($theme_color(urls)),$chr(31),$gettok(%line,%x,32),$chr(31),$clr)
        %line = $puttok(%line,%l2,%x,32)
      } 
      inc %x 
    }
  }
  return %line
}

$theme_color(urls) returns the color of the text i want to echo, in my case 02..
Posted By: 5618 Re: $regex prob - 19/06/07 09:31 AM
Errrr....

$regex(%line,/(\b(www.?\.|https?:\/\/|ftp:\/\/|unreal://\/\/).)/i)

You escape the slashes in https:// and ftp:// but not in [url=unreal://.][url=unreal://.][url=unreal://.]unreal://.[/url][/url][/url] Remove the first two slashes, which I assume you forgot to delete.
Posted By: sparta Re: $regex prob - 19/06/07 09:41 AM
i forgot that one, but still no luck, i wont get the script to trigger on it
Posted By: schaefer31 Re: $regex prob *DELETED* - 19/06/07 10:22 AM
Post deleted by schaefer31
Posted By: sparta Re: $regex prob - 19/06/07 10:35 AM
i tested your code, but the only thing i got was that the color for it was f*ed up, and no reaction on unreal:, dunno why it's so hard to get it to work on just that one, dont know if it's cos it's not a default link in mirc, www - http - ftp do mirc it self react on, but unreal is a hotlink i created..

;--------------- EDIT

the code i trying to learn from can be found http://script.quakenet.org/wiki/How_to_make_your_own_theme

since im new to $regex i cant solve it, how ever i trying to learn it. Any help would be usefull smile
Posted By: schaefer31 Re: $regex prob - 19/06/07 10:46 AM
I don't know why you seem to have trouble triggering on unreal://, it works as expected for me.

Actually you can just use $regsubex instead of looping like you are. mIRC 6.17 or later required, which I assume you're using.

Try this, I used only simple underline replacement as a test since I don't know what your custom identifiers do.

Code:
alias urltheme {
  return $regsubex($1,/((?:(?:unreal|ftp|https?):\/\/|www\.)\S+)/Sgi,$+(,\t,))
}


//echo -ag $urltheme(abc http://mirc.com def https://mirc.com ghi ftp://mirc.com jkl [url=unreal://m.i.r.c][url=unreal://m.i.r.c][url=unreal://m.i.r.c]unreal://m.i.r.c[/url][/url][/url] mno www.mirc.com)

returns abc http://mirc.com def https://mirc.com ghi ftp://mirc.com jkl [url=unreal://m.i.r.c][url=unreal://m.i.r.c][url=unreal://m.i.r.c]unreal://m.i.r.c[/url][/url][/url] mno www.mirc.com

Works as expected.


And here's the same code using your identifiers:
Code:
alias urltheme {
    return $regsubex($1,/((?:(?:unreal|ftp|https?):\/\/|www\.)\S+)/Sgi,$+($clr($theme_color(urls)),$chr(31),\t,$chr(31),$clr))
}


Posted By: sparta Re: $regex prob - 19/06/07 10:58 AM
thanx for your help, i trying to learn, i will look at your code, then see if i can understand what everything is doing smile
Posted By: MeStinkBAD Re: $regex prob - 19/06/07 04:21 PM
Originally Posted By: sparta
thanx for your help, i trying to learn, i will look at your code, then see if i can understand what everything is doing smile


I'd use...
Code:
$regsubex($1,/((?:(?:[a-zA-Z0-9]*?):\/\/|www\.)\S+)/Sgi,$+(,\t,))


THough i would really rather not use regular expressions for this. Rather evalutate the line with a rather complex loop that advances one character every interation.
Posted By: schaefer31 Re: $regex prob - 19/06/07 05:22 PM
No need to over complicate things. a-zA-Z0-9 is effectively the same as using \w (effectively because \w also includes underscores, shouldn't be a problem). a-zA-Z is not necessary in this case either since the "i" modifier is used, just a-z or A-Z will do, don't need both. Also using *? here will cause it to underline even if no protocol is specified, in which case I believe it shouldn't. Better to use "+" (1 or more chars). You can also drop the inner most set of grouping brackets, since you're no longer specifying alternations.

Code:
alias urltheme return $regsubex($1,/((?:\w+:\/\/|www\.)\S+)/Sgi,$+($clr($theme_color(link)),$chr(31),\t,$chr(31),$clr))


Although personally, I'd rather just worry about common protocols.
Posted By: Mpdreamz Re: $regex prob - 19/06/07 05:38 PM
Quote:

THough i would really rather not use regular expressions for this. Rather evalutate the line with a rather complex loop that advances one character every interation.


how do you think regular expressions are processed ? :P
© mIRC Discussion Forums