mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2005
Posts: 122
O
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.

Joined: Oct 2005
Posts: 1,741
G
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

Joined: Oct 2005
Posts: 122
O
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.
Joined: Oct 2005
Posts: 122
O
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

Joined: Nov 2006
Posts: 1,559
H
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 -


Joined: Oct 2005
Posts: 122
O
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


Link Copied to Clipboard