mIRC Home    About    Download    Register    News    Help

Print Thread
keyword replacement using regex? #224776 18/08/10 11:05 AM
Joined: Nov 2003
Posts: 82
C
colt45 Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Nov 2003
Posts: 82
Not sure how or where to start...
What I'd like to do is to tell me which one has been detected.
Excuse my poor english but let me show you example what I'm trying to do and maybe you can help me solve this?
Thanks

I want to capture $1- as an example
Quote:

The quick brown fox jumps over the lazy dog

I'm hoping to use regex
i.e.
Code:
($regex($1-,/(cow|dog|fox|pigs)/i))

So in return, I'd like to display it something like this..
Quote:

Word detected : The quick brown fox jumps over the lazy dog

Hope one of you can help me out here .. thanks

Re: keyword replacement using regex? [Re: colt45] #224777 18/08/10 11:23 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
you can use $regsubex() to perform substitutions on the portions of the text matched by your regular expression:

Code:
$regsubex($1-, /(cow|dog|fox|pigs)/gi, $chr(3) $+ 4\1$chr(15))


the 'g' modifier tells the regex engine to continue past the first successful match. \1 in the 3rd (substitution) parameter returns the substring captured by the first (group) in the expression.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: keyword replacement using regex? [Re: jaytea] #224778 18/08/10 12:24 PM
Joined: Nov 2003
Posts: 82
C
colt45 Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Nov 2003
Posts: 82
That $regsubex() is exactly what i was looking for! laugh

Also, where did you find that /g switch from? - It not in the mirc.chm tho (i'm using v6.35 - will upgrade to 7.1 but too scare it might breaks my script! :p)

Many thanks for the reply tho smile

Re: keyword replacement using regex? [Re: colt45] #224779 18/08/10 12:52 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The help file doesn't list a LOT of what you can do with regex. You'll want to look up regex information with Google to find all of the things you can do with it that aren't shown in the help file.


Invision Support
#Invision on irc.irchighway.net
Re: keyword replacement using regex? [Re: Riamus2] #224780 18/08/10 01:09 PM
Joined: Nov 2003
Posts: 82
C
colt45 Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Nov 2003
Posts: 82
I have this bad habit as I rely on mirc.chm but will try start using google more smile

Thanks smile

Re: keyword replacement using regex? [Re: colt45] #224787 18/08/10 05:13 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: colt45
where did you find that /g switch from?
The /g is a regex modifier. You can learn about it via any online search engines or local book stores to find out what it means and does. The /g modifier simply makes the regex match something you're after globally or in a "greedy" manner. Without using it, the regex will only match the first string that it finds and stops.

Re: keyword replacement using regex? [Re: Tomao] #224849 19/08/10 11:45 PM
Joined: Nov 2003
Posts: 82
C
colt45 Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Nov 2003
Posts: 82
Originally Posted By: Tomao
Originally Posted By: colt45
where did you find that /g switch from?
The /g is a regex modifier. You can learn about it via any online search engines or local book stores to find out what it means and does. The /g modifier simply makes the regex match something you're after globally or in a "greedy" manner. Without using it, the regex will only match the first string that it finds and stops.


Noted smile

Thanks ..

Re: keyword replacement using regex? [Re: jaytea] #224903 21/08/10 01:36 PM
Joined: Sep 2007
Posts: 109
K
kwell Offline
Vogon poet
Offline
Vogon poet
K
Joined: Sep 2007
Posts: 109
Used to color the nicknames of the channel?
Code:
on *:INPUT:#: {
  if ($left($1,1) != /) { 
    .msg $active $regsubex($1-, /( $nick )/gi, $chr(3) $+ 4\1$chr(15))
  }
}

Last edited by kwell; 21/08/10 01:36 PM.
Re: keyword replacement using regex? [Re: kwell] #224909 21/08/10 03:43 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
kwell, your example will fail to work.