mIRC Homepage
Posted By: vexed2 regsubex - 22/12/07 04:35 PM
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.
Posted By: TropNul Re: resubex - 22/12/07 05:09 PM
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
Posted By: genius_at_work Re: regsubex - 22/12/07 06:03 PM
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
Posted By: vexed2 Re: regsubex - 30/12/07 07:04 PM
sorry, not been on for a while, thanks to both of you smile
© mIRC Discussion Forums