mIRC Homepage
Posted By: oliverw92 $regsubex marker suggestion - 14/07/07 08:34 PM
the other day i was trying to make something to remove duplicate letters in words

e.g. hello would turn to helo, elle would turn into el etc.

however i was having to do it a very long way. my suggestions is the \p special marker, which returns "previously substituted text".

example:

$regsubex(elle,/(.)/g,$iif(\1 !isin \p,\1))

would return el

$regsubex(extreme,/(.)/g,$iif(\1 !isin \p,\1))

would return extrm

i dont know whether \p is already in use in regex, if not, antoher letter. i have a feeling this could be very useful. thanks for ur time, hope this gets added!
Posted By: qwerty Re: $regsubex marker suggestion - 14/07/07 09:49 PM
If by "previously substituted text" you mean a string of all $iif(\1 !isin \p,\1)'s up to that step (ie a string of all newly encountered \1's), I agree, it could be useful.

Meanwhile, your specific problem can be solved with something like this:
//echo -ag $regsubex(extreme,/(.)/g,$iif(!$pos($left(\A,\n),\1,2),\1))

If you just want to keep unique letters, and not each first unique letter, you can also do this:
//echo -ag $regsubex(extreme,/(.)(?=.*\1)/g,)

Another imo useful marker would be an incremental equivalent of \A, ie a marker being the string of captured substrings up to the \n-th iteration
Posted By: oliverw92 Re: $regsubex marker suggestion - 15/07/07 12:24 AM
ah another good idea. and thanks for the help in that. i had something similar but it was it overly complicated.
Posted By: Mpdreamz Re: $regsubex marker suggestion - 15/07/07 04:12 PM
Damnit qwerty you just spoilered the method i had set a challenge around. Although it can be shorter smile

Anyhow i support both suggestions.
Posted By: qwerty Re: $regsubex marker suggestion - 15/07/07 06:56 PM
It can be shortened indeed (not sure if that's what you had in mind, ie if I further ruined your challenge :P)

//echo -ag $regsubex(extreme,/(.)/g,$iif($pos(\A,\1) == \n,\1))

It's not only shorter but more intuitive and slightly faster. Funny how often the simplest solutions are the last to come to mind.
Posted By: oliverw92 Re: $regsubex marker suggestion - 16/07/07 08:09 AM
whast the likely hood of this being accepted?
Posted By: Mpdreamz Re: $regsubex marker suggestion - 17/07/07 06:20 PM
I previously suggested \A and that got added so who knows smile
It would rock though smile
© mIRC Discussion Forums