mIRC Homepage
Posted By: onesikgypo Assistance required with a regex - 22/11/08 04:47 AM
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.
Posted By: genius_at_work Re: Assistance required with a regex - 22/11/08 04:58 AM
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
Posted By: onesikgypo Re: Assistance required with a regex - 22/11/08 07:19 AM
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))
Posted By: onesikgypo Re: Assistance required with a regex - 27/12/08 11:34 AM
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
Posted By: Horstl Re: Assistance required with a regex - 27/12/08 03:23 PM
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 -

Posted By: onesikgypo Re: Assistance required with a regex - 27/12/08 03:44 PM
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
© mIRC Discussion Forums