mIRC Home    About    Download    Register    News    Help

Print Thread
#180881 14/07/07 08:34 PM
Joined: Apr 2007
Posts: 8
O
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
O
Joined: Apr 2007
Posts: 8
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!

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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

Last edited by qwerty; 15/07/07 12:00 AM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Apr 2007
Posts: 8
O
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
O
Joined: Apr 2007
Posts: 8
ah another good idea. and thanks for the help in that. i had something similar but it was it overly complicated.

Last edited by oliverw92; 15/07/07 12:30 AM.
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Damnit qwerty you just spoilered the method i had set a challenge around. Although it can be shorter smile

Anyhow i support both suggestions.


$maybe
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Apr 2007
Posts: 8
O
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
O
Joined: Apr 2007
Posts: 8
whast the likely hood of this being accepted?

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
I previously suggested \A and that got added so who knows smile
It would rock though smile


$maybe

Link Copied to Clipboard