mIRC Home    About    Download    Register    News    Help

Print Thread
Removing occurrences using regex #133095 17/10/05 07:01 AM
Joined: Dec 2004
Posts: 81
N
nycdiesel Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Dec 2004
Posts: 81
I've written an alis to do this already just wondering if it's possible to do this using regex? I've tried the following but it only strips one occurrence:

Code:
//var %reg = (\w+\b)\s | echo -a $regsub(test blah test this is a test,%reg,$chr(32),%var) | echo -a %var


Output

blah test this is a test

Re: Removing occurrences using regex #133096 17/10/05 07:52 AM
Joined: Jun 2005
Posts: 11
H
hantu Offline
Pikka bird
Offline
Pikka bird
H
Joined: Jun 2005
Posts: 11
Remove occurences of what? smile


- hantu
Re: Removing occurrences using regex #133097 17/10/05 08:05 AM
Joined: Dec 2004
Posts: 81
N
nycdiesel Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Dec 2004
Posts: 81
Words. Words appearing more than once in a string.

Re: Removing occurrences using regex #133098 17/10/05 09:43 AM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
use the /g option so it replaces all the matches in the string


$maybe
Re: Removing occurrences using regex #133099 17/10/05 06:14 PM
Joined: Jul 2003
Posts: 655
Om3n Offline
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Indeed, and grep's should always be surrounded by //'s in mirc scripting

var %reg = /(\w+\b)\s/g


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Re: Removing occurrences using regex #133100 18/10/05 10:40 AM
Joined: Aug 2003
Posts: 314
S
Sigh Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
This alias removes words closer to the beginning of the string if they already exist as words further on:

Code:
remrpts var %i | return $(,,$regsub($1,/(?:^| )([^ ]+)(?= )(?=.* \1(?: |$))/gs,,%i)) %i

Re: Removing occurrences using regex #133101 18/10/05 12:29 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Nice usage of $eval, I'll remember that one. Much preferable over $null which can be overriden by a scripted version, unlike $()


Gone.
Re: Removing occurrences using regex #133102 18/10/05 01:15 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Nice indeed smile Shorter and a tiny bit faster than !.echo -q (although the difference is really really small, almost immeasurable. The identifier call overhead seems to almost match up with the one of the extra command). Definitely gonna use it.

$() is weird, you can find other little oddities if you play with it. So far the only one I'm probably going to use is $(,stuff) which is the same as $(stuff,2) , only a tiny bit faster. Oh and I believe you know about $(stuff,) already (which is the same as $(stuff,0)).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Removing occurrences using regex #133103 18/10/05 01:18 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Quote:
So far the only one I'm probably going to use is $(,stuff) which is the same as $(stuff,2) , only a tiny bit faster. Oh and I believe you know about $(stuff,) already (which is the same as $(stuff,0)).

I didn't know about $(,stuff) being $(stuff,2)

Yes, I've used the $(stuff,) one heavily when passing code to scon, although nowadays, I try to steer away from passing code to scon in that way. Too many people, who are unaware of the dangers etc. copy the code, modify it, and then come back complaining that it doesn't work :tongue:

Btw I would reckon multiple identifiers have this sort of behaviour as what Sigh_ did, check out:

//echo -a $time(,$regex(b,(.))) $regml(1)

Another thing I only found out recently is that if you have a scripted version for an identifer like:

alias me return lol

You can make it return the scripted version by putting $me(), instead of doing $.me or $/me etc
But I'm guessing you already knew that anyway :tongue:

Last edited by FiberOPtics; 18/10/05 01:36 PM.