mIRC Home    About    Download    Register    News    Help

Print Thread
Assistance required with a regex #206710 22/11/08 04:47 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
Hi,

I just have a simple question, what would the regex match be to remove all non alphanumbers (.'s _'s -'s ()'s etc.) from a string, i believe this is something easily done via regex, however as im not familiar with it im having trouble. I know the script will be like this:

Code:
if ($regex($1,regexmatch)) { return $regml(1) }


I just dont know what should be where "Regxmatch" is.

Any Assitance would be greatly appreciated.

Thankyou.

Re: Assistance required with a regex [Re: onesikgypo] #206711 22/11/08 04:58 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
To remove all non-alphanum characters, use something like this:

echo -a $regsubex(%text,/([^a-z0-9])/gi,)

You may want to keep space characters too:

echo -a $regsubex(%text,/([^a-z0-9 ])/gi,)

-genius_at_work

Re: Assistance required with a regex [Re: genius_at_work] #206713 22/11/08 07:19 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
Thankyou, that worked great, but ive just realised that id need a refinement, and instead of simply removing the non alphanum chars, replace them with spaces ?


Edit: NVM Figured it out, for anybody wanting to know:
Code:
echo -s $regsubex(%text,/[^a-z0-9]/gi,$chr(32))

Last edited by onesikgypo; 22/11/08 07:21 AM.
Re: Assistance required with a regex [Re: onesikgypo] #207661 27/12/08 11:34 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
i have a follow up question, though i know its been some time since the original post, but the above will not work when there is only one alphanum char left, i.e [a] will not return a, but [ab] will return ab - any help would be greatly appreciated

Re: Assistance required with a regex [Re: onesikgypo] #207664 27/12/08 03:23 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
It's working fine for me - could you provide the actual code you're using?
The extra "-" below are to visualise the leading/trailing spaces, which mIRC wouldn't show in the echo output.

//var %text = [a,b] | echo -a - $+ $regsubex(%text,/[^a-z0-9]/gi,$chr(32)) $+ -
echoes (as expected): - a b -

//var %text = [a] | echo -a - $+ $regsubex(%text,/[^a-z0-9]/gi,$chr(32)) $+ -
echoes (as expected): - a -


Re: Assistance required with a regex [Re: Horstl] #207665 27/12/08 03:44 PM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
ah your right, its my stupid mistake, i forgot to fix the coding in one part of the script and it was using an old redundent code

if ( $regex($1,/(\w.*\w)/i) ) { return $regml(1) }

but its all fine as i use the new one