mIRC Home    About    Download    Register    News    Help

Print Thread
Praying to the $regex gods. #182477 10/08/07 03:11 AM
Joined: Aug 2007
Posts: 8
C
Colby Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Aug 2007
Posts: 8
Im looking for a few $regex strings for picking up *true* emails and URLs, so I can add a color code/underline to them.

Pretty please?

Re: Praying to the $regex gods. [Re: Colby] #182478 10/08/07 03:26 AM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline
Fjord artisan
Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Underlining them would be simple.

%variable = $replace(%variable,not underlined,underlined)

Then you can use %variable wherever, in $regex(), etc.

Re: Praying to the $regex gods. [Re: Colby] #182481 10/08/07 04:51 AM
Joined: Feb 2005
Posts: 342
R
Rand Offline
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
I'm not sure where you're wanting to pull the emails and urls from, if it's from HTML (sockets), then you could probably use something like: $regex(%text,/<(\S+?@\S+?\.\S+?)>/g)

That would consider: <email@host.com> as an email, but not: <email@localhost> or <email @ localhost> of course if you want to include spaces as the true emails, you could use something like: .*? instead of those \S+?


On the other hand, if you're just parsing plain text on IRC, something a little more tricky then, there's stuff you could match for, but it really depends. Like: [^<@, ]* and stuff, I don't have enough time to go look up all the allowed characters for each protocol and what not, but if you're parsing plain text through something like "on text" on IRC, you could probably use something like: $regex($1-,/([^<@> ]*@[^<@> ]*\.[^<@> ]*)/g)

Anyway, good luck.

Quick example:
Code:
//tokenize 32 this is a test <a@bcd.com> hehe <afd@hij.hehe.com> also haha.yeah@blah.com | echo -a $regsubex($1-,/([^<@> ]*@[^<@> ]*\.[^<@> ]*)/g,\t)

Re: Praying to the $regex gods. [Re: Colby] #182483 10/08/07 05:03 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
There was a nice "library of regular expressions" at merlin's page (hope this site is back soon). That "mIRC script box" I'm refering to has been available online and offline - You possibly know someone who did download the "mScriptBox.chm". For my part, thats all I can offer - Let's wait for the gods wink


Re: Praying to the $regex gods. [Re: Colby] #182497 10/08/07 08:31 AM
Joined: Aug 2007
Posts: 8
C
Colby Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Aug 2007
Posts: 8
Sorry, it seems I was a little unspecific. I am looking for a way to replace the text in the channel to underline and color *true* emails/URLs.

So, for example, someone says in a channel "go to http://www.mirc.com and see for yourself!" I want the full URL to be blue and underlined.

Or if someone says "Email me at moo@mirc.com" I would like the email to be red and underlined.

I hope this helps. *Prays for regex gods. :D*

Re: Praying to the $regex gods. [Re: Colby] #182501 10/08/07 12:05 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
You could do it without the use of regex for now, using regex of course would probably shorten the code considerably and perhaps be just a little faster too? I don't know.

Code:
On ^*:Text:*:#: {
  var %trgt = $iif($target ischan,$chan,$nick)
  if (Email me at isin $1-) && ($wildtok($1-,*@*,1,32)) { echo -t %trgt $+(<,$nick,>) $+(4,Email me at $ifmatch,) | halt }
  if (*http:* iswm $1-) || (*www.* iswm $1-) || (*ftp:* iswm $1-) || (*mailto:* iswm $1-) {
    if ($wildtok($1-,$ifmatch,1,32)) { echo %trgt $+(<,$nick,>) $replace($1-,$ifmatch,$+(12,$ifmatch,)) | halt }
  }
}

on ^1:HOTLINK:*:#:{
  if (*http:* iswm $hotline) || (*www.* iswm $hotline) || (*ftp:* iswm $hotline) || (*mailto:* iswm $hotline) {
    if ($1 == $wildtok($1-,$ifmatch,1,32)) && ($mouse.key == 1) run $1
  }
  if (Email me at isin $hotline) && ($wildtok($1-,*@*,1,32) isin $hotline) {
    if ($mouse.key == 1) run $+(mailto:,$wildtok($1-,*@*,1,32))
  }
  halt
}

Re: Praying to the $regex gods. [Re: SladeKraven] #182549 10/08/07 11:38 PM
Joined: Aug 2007
Posts: 8
C
Colby Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Aug 2007
Posts: 8
Yea, thanks, but that is the reason for me wanting regex, is for the shorter/faster code. I dont like things hardcoded, per se.

Re: Praying to the $regex gods. [Re: Colby] #182558 11/08/07 01:04 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I use this section of code to identify www links:

Code:
  var %string = $1-, %islink = $false
  if ($regex(%string,/(www\.|http\:|\.com|\.net|\.org|irc\.|\/server)/i)) %islink = $true
  if ($regex(%string,/[aeo]wwww*\./ig)) %islink = $false
  if (%islink) echo -a This text contains a link.


Technically, it is for detecting spammers, but you should be able to modify it to suit your needs.

www links are harder to detect than email links because there isn't an easily identifiable character (@).

-genius_at_work

Re: Praying to the $regex gods. [Re: genius_at_work] #182560 11/08/07 03:48 AM
Joined: Aug 2007
Posts: 8
C
Colby Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Aug 2007
Posts: 8
Would I be able to use $regml to pull just the link itself?

Re: Praying to the $regex gods. [Re: Colby] #182564 11/08/07 05:18 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Code:
alias re.link return (?:\w+\:\/\/)?[\w\.]+\.(?:com|net|org|biz|us|ca|uk)(?:[\w\/\%\.]*?)
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
}



Example: //echo -a $makelinks(This email@address.org has a http://www.link.com/path/file.html)

-genius_at_work