|
Joined: Aug 2007
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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?
|
|
|
|
Joined: Jan 2004
Posts: 509
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: Feb 2005
Posts: 342
Fjord artisan
|
Fjord artisan
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: //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)
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Aug 2007
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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*
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
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.
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
}
|
|
|
|
Joined: Aug 2007
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
I use this section of code to identify www links:
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
|
|
|
|
Joined: Aug 2007
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Aug 2007
Posts: 8 |
Would I be able to use $regml to pull just the link itself?
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
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
|
|
|
|
|