RegExp 匹配重复字符 [英] RegExp match repeated characters
本文介绍了RegExp 匹配重复字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如我有字符串:
aacbbbqq
因此我想要以下匹配项:
As the result I want to have following matches:
(aa, c, bbb, qq)
我知道我可以这样写:
([a]+)|([b]+)|([c]+)|...
但我认为我很丑,正在寻找更好的解决方案.我正在寻找正则表达式解决方案,而不是自己编写的有限状态机.
But I think i's ugly and looking for better solution. I'm looking for regular expression solution, not self-written finite-state machines.
推荐答案
你可以匹配:(\w)\1*
这篇关于RegExp 匹配重复字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文