RegSubEx Strip/Remove

Platform:  mIRC
Published  Dec 21, 2010
Updated  Dec 29, 2010
I was getting tired of always having to do $strip and $remove separately and also wanted to try and use regsubex to remove.
Anything you want removed from the string just input into $prop

Usage: //echo -a $strp(@test1 !test2 wtest3 Wtest4).@!w
This will return: test1 test2 test3 Wtest4



I would love feedback on a better/more proper way to code using regsubex. ;) alias strp {
var %x, %a $strip($1), %b $prop, %c $iif($2,$v1,g),%d /[ $+ %b $+ ]/ $+ %c
.echo -q $regsub(%a,%d,,%x) | return %x
}

Comments

Sign in to comment.
Akwill   -  Dec 29, 2010
Wow thank you for the feedback guys, I appreciate it!

I added optional $2, that way I can put in different modifiers like i or g at will.
 Respond  
Jethro   -  Dec 21, 2010
Thank you for the heads up, jaytea. This is informative.
 Respond  
jaytea   -  Dec 21, 2010
there are many more combinations of characters that are significant inside a character class than simple generic types such as \d and \D, eg: $strp().^a (negation); $strp().a-z (range); $strp().a]b; $strip().[:digit:] (POSIX class); etc.

if ever you want to insert a piece of text inside a regex and have it treated literally, you can use \Q and \E to quote a substring:

Code

 


$replacecs() is used in case %r contains '\E'.
 Respond  
Jethro   -  Dec 21, 2010
Very well, Scakk. You can also use regex POSIX:

Code

 
and

Code

 
 Respond  
Scakk   -  Dec 21, 2010
Example:

This -> //echo -a $strp(@test1 !test2 #wtest3 Wtest4).\d
Returns -> @test !test #wtest Wtest

This -> //echo -a $strp(@test1 !test2 #wtest3 Wtest4).\D
Returns -> 1234
 Respond  
Jethro   -  Dec 21, 2010

Quote

Personally I would not use /i as people may only want to remove the lower case or upper case characters.
Yes, Scakk. It was an added info and for example purposes only. I'm not sure what you mean by \d and \D. One means digit and the other non-digit.
 Respond  
Scakk   -  Dec 21, 2010
Personally I would not use /i as people may only want to remove the lower case or upper case characters.

Also with the \ removed from the %r variable you can use \d \D and such in the prop and it will work like a normal $regsubex for the whole string.
 Respond  
Jethro   -  Dec 21, 2010
Nice work and concept, Akwill. One thing you didn't have to do is include the $null. It's not needed. Also, as per your example, and I quote,

Quote

$strp(@test1 !test2 wtest3 Wtest4).@!w
The last strip is Wtest4 with a capital letter w. Regex by design is case sensitive, so if you want that to get removed as well, you need to add the /i modifier next the /g to make it case-insensitive, and you get

Quote

test1 test2 test3 test4

Code

 
And the $regsub() version for those who use older mIRC versions that don't support the identifier $regsubex() and noop command:

Code

 


 Respond  
Scakk   -  Dec 21, 2010
There is an issue when you place a number in the prop by itself. It will not remove the number. If it is in the prop with anything else , even if not in the string , it will remove the number.

If you change the %r to be

Code

 
it will worrk properly.
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.