mIRC Home    About    Download    Register    News    Help

Print Thread
$regex prob #179211
19/06/07 08:43 AM
19/06/07 08:43 AM
Joined: Feb 2003
Posts: 3,432
Sweden/Borlänge
S
sparta Offline OP
Hoopy frood
sparta  Offline OP
Hoopy frood
S

Joined: Feb 2003
Posts: 3,432
Sweden/Borlänge
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..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $regex prob [Re: sparta] #179213
19/06/07 09:31 AM
19/06/07 09:31 AM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
5618  Offline
Hoopy frood
5

Joined: Jun 2007
Posts: 933
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.

Re: $regex prob [Re: 5618] #179214
19/06/07 09:41 AM
19/06/07 09:41 AM
Joined: Feb 2003
Posts: 3,432
Sweden/Borlänge
S
sparta Offline OP
Hoopy frood
sparta  Offline OP
Hoopy frood
S

Joined: Feb 2003
Posts: 3,432
Sweden/Borlänge
i forgot that one, but still no luck, i wont get the script to trigger on it


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $regex prob *DELETED* [Re: sparta] #179215
19/06/07 10:22 AM
19/06/07 10:22 AM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline
Fjord artisan
schaefer31  Offline
Fjord artisan
S

Joined: Aug 2005
Posts: 525
Post deleted by schaefer31

Re: $regex prob [Re: schaefer31] #179216
19/06/07 10:35 AM
19/06/07 10:35 AM
Joined: Feb 2003
Posts: 3,432
Sweden/Borlänge
S
sparta Offline OP
Hoopy frood
sparta  Offline OP
Hoopy frood
S

Joined: Feb 2003
Posts: 3,432
Sweden/Borlänge
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

Last edited by sparta; 19/06/07 10:40 AM.

if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $regex prob [Re: sparta] #179220
19/06/07 10:46 AM
19/06/07 10:46 AM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline
Fjord artisan
schaefer31  Offline
Fjord artisan
S

Joined: Aug 2005
Posts: 525
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))
}



Re: $regex prob [Re: schaefer31] #179221
19/06/07 10:58 AM
19/06/07 10:58 AM
Joined: Feb 2003
Posts: 3,432
Sweden/Borlänge
S
sparta Offline OP
Hoopy frood
sparta  Offline OP
Hoopy frood
S

Joined: Feb 2003
Posts: 3,432
Sweden/Borlänge
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


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $regex prob [Re: sparta] #179238
19/06/07 04:21 PM
19/06/07 04:21 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
MeStinkBAD  Offline
Fjord artisan
M

Joined: Apr 2003
Posts: 342
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.


Beware of MeStinkBAD! He knows more than he actually does!
Re: $regex prob [Re: MeStinkBAD] #179245
19/06/07 05:22 PM
19/06/07 05:22 PM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline
Fjord artisan
schaefer31  Offline
Fjord artisan
S

Joined: Aug 2005
Posts: 525
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.

Re: $regex prob [Re: MeStinkBAD] #179247
19/06/07 05:38 PM
19/06/07 05:38 PM
Joined: Apr 2004
Posts: 759
Arnhem, The Netherlands
M
Mpdreamz Offline
Hoopy frood
Mpdreamz  Offline
Hoopy frood
M

Joined: Apr 2004
Posts: 759
Arnhem, The Netherlands
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


$maybe