Reputation: 8636
Need a regular expression to replace the following sequence
Before : abbbccdd After : abcd
And also if numeric data is present instead of alphabets i would like to remove the duplicates and display
Upvotes: 2
Views: 2330
Reputation: 49
This works in PHP:
preg_replace('/(.)\1+/','$1',$str);
I'm not sure what you mean with your second question, though.
Upvotes: 0
Reputation: 838186
For the first part, in most languages you can do something like replacing (.)\1+
with $1
.
The exact syntax depends on the language and the regular expression engine you are using, so check the manual for your language for more details.
Upvotes: 5