Community Patterns

Community Library Entry

1

Regular Expression
Created·2020-07-16 19:31
Flavor·PCRE (Legacy)

Description

In an interview, I was asked to remove all repeating adjacent characters in a string except one. For example, input : abbccasdjajksdhkjaaaaa output : abcasdjajksdhkja

In Java, the syntax will be s.replaceAll("(.)\\1{1,}", "$1");

where s is the input string.

Submitted by anonymous