[PYTHON] php continuous characters in one

Thing you want to do

I want to make a string like ABBCCCAA ABCA

This is okay

PHP

>>>  preg_replace('/(.)\1+/', '\1', 'ABBCCCAA')
=> "ABCA"

JS

'ABBCCCAA'.replace(/(.)\1+/g, '$1')
=> "ABCA"

ruby

"ABBCCCAA".gsub(/(.)\1+/, '\1')
=> "ABCA"

python

import re
print(re.sub(r'(.)\1+', '\\1', 'ABBCCCAA'))

=> "ABCA"

end

Similar articles

https://qiita.com/nena3/items/b5fec48c8eecb2353ab1

Recommended Posts

php continuous characters in one
One liner in Python
PHP var_dump in Django templates
Fizzbuzz in Python (in one line)
DMD in Python one dimension
[Python] [3D line graph] Multiple data in one graph, axis values in characters
Make python segfault in one line
Display characters like AA in python
How to convert 0.5 to 1056964608 in one shot
Prime number enumeration in one line
Segfault with 16 characters in C language