I want to make a string like ABBCCCAA ABCA
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