Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? remove adjacent common chars

samintz

Scott Mintz
May
1,590
27
Is there a simple way to compress a string by reducing the common adjacent characters to a single character? For example a path string with multiple ;;;; reduced to a single ;.

Or multiple spaces reduced to a single space.

SIMPLE being the operative word here.

-Scott
 
Regex replace
Code:
(.){2,}
with
Code:
\1

Edit: OK. That didn't work as great in practice as it sounded in my head. I'm still working on it.
Edit: Here's an updated search string.
Code:
(.)\1+
Edit: Here's an example using sed
Code:
set | sed -r -e "s/(.)\1+/\1/g"
Edit: Make sure to replace the "(.)" with something like "([; ])" or whatever characters you're actually wanting to replace or you'll end up taking out other characters that you want to keep.
 
Since this is kind of a one-off need, I just used this:
Code:
do while %@index[%newp,;;] != -1 (set newp=%@replace[;;,;,%newp])
 
Back
Top
[FOX] Ultimate Translator
Translate