0
0

More than 3 years have passed since last update.

php 連続 文字 一つに

Last updated at Posted at 2019-12-26

やりたいこと

ABBCCCAAのような文字列をABCAにしたい

これでおk

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"

おわり

類似記事

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0