mIRC Home    About    Download    Register    News    Help

Print Thread
regsubex #192121 22/12/07 04:35 PM
Joined: Mar 2007
Posts: 218
V
vexed2 Offline OP
Fjord artisan
OP Offline
Fjord artisan
V
Joined: Mar 2007
Posts: 218
I've got this alias for underlining urls/irc/email links which i got from here.
I've just noticed though, it doesn't underline the / character it contains one, ie;

www.mirc.com works fine
www.mirc.com/ the / doesn't get underlined

Code:
alias urlu {
  return $regsubex($1-,/\b(\^@\S+|www\.\S+|http://\S+|irc\.\S+|irc://\S+|\w+(?:[\.-]\w+)?@\w+(?:[\.-]\w+)?\.[a-z]{2,4})\b/gi,$+(10,\1,))
}


Not knowing about regsubex i needed to ask here, and help gladly appreciated.

Last edited by vexed2; 22/12/07 05:06 PM.
Re: resubex [Re: vexed2] #192123 22/12/07 05:09 PM
Joined: May 2007
Posts: 89
T
TropNul Offline
Babel fish
Offline
Babel fish
T
Joined: May 2007
Posts: 89
Ok, I spotted the problem.

It's because of the \b at the end completely of the pattern. The \b means "word boundary (the zero-width point between a character that forms part of the word \w class and a character that forms part of the non-word \W class)" and as / doesn't form part of the \w class, it's not considered in the match, although the \S+ "until it finds a space" class is used.

Here's a possible solution.

Code:
alias urlu {
  return $regsubex($1-,/\b(\^@\S+|www\.\S+|http://\S+|irc\.\S+|irc://\S+|\w+(?:[\.-]\w+)?@\w+(?:[\.-]\w+)?\.[a-z]{2,4})(?(?<=/)|\b)/gi,$+(10,\1,))
}


I've used some conditional for a casewise match. But you could as well use the following solution.

Code:
alias urlu {
  return $regsubex($1-,/\b(\^@\S+|www\.\S+|http://\S+|irc\.\S+|irc://\S+|\w+(?:[\.-]\w+)?@\w+(?:[\.-]\w+)?\.[a-z]{2,4})/gi,$+(10,\1,))
}


By the way, here's yet another solution with a better pattern.

Code:
alias urlu {
  return $regsubex($1-,/\b(www\.\S+|http://\S+|irc(\.|://)\S+|\w+(?:[\.-]\w+)?@\w+(?:[\.-]\w+)?\.[a-z]{2,4})/gi,$+(10,\1,))
}


Hope this helps you.

Cordialement


tropnul
Re: regsubex [Re: vexed2] #192127 22/12/07 06:03 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Here is a script I made for someone on this forum. It may be useful to you.

Code:
alias re.link return (?:\w+\:\/\/)?[\w\.]+\.(?:com|net|org|biz|us|ca|uk|\d\d?\d?)(?:\S*)
alias re.mail return [\w.]+\@[\w.]+

alias makelinks {
  var %s = $1-
  %s = $regsubex(%s,/( $+ $re.mail $+ )/gi,04\1)
  %s = $regsubex(%s,/(?<=\s)( $+ $re.link $+ )(?=\s)/gi,12\1)
  return %s
}

on ^*:HOTLINK:*:*:{
  var %halt = 1
  if ($regex($1,/ $+ $re.mail $+ /i)) %halt = 0
  elseif ($regex($1,/ $+ $re.link $+ /i)) %halt = 0
  if (%halt) halt
}

on *:HOTLINK:*:*:{
  if ($regex($1,/ $+ $re.mail $+ /i)) run mailto: $+ $1
  elseif ($regex($1,/ $+ $re.link $+ /i)) run $1
}



Usage: $makelinks(<text>)

It underlines anything that is a proper url (begins with xxx://).

It is more specific than you may want. It only matches the top level domains that are specified (you can change them). If you, or someone so chooses, they could make an alias that returns every TLD separated by |'s and use that instead.

I just pulled it out of my scripts folder, so it may not do exactly what you want.

-genius_at_work

Re: regsubex [Re: genius_at_work] #192381 30/12/07 07:04 PM
Joined: Mar 2007
Posts: 218
V
vexed2 Offline OP
Fjord artisan
OP Offline
Fjord artisan
V
Joined: Mar 2007
Posts: 218
sorry, not been on for a while, thanks to both of you smile