Regular expression to match character repeated three times

后端 未结 2 921
失恋的感觉
失恋的感觉 2020-12-18 06:12

I need to simplify the following regular expression to include all the letters of the alphabet:

(a{3})|(b{3})|(c{3})|(z{3})|(A{3})|(B{3})|(C{3})|(Z{3})


        
相关标签:
2条回答
  • 2020-12-18 06:41

    Use backreferences. Eg. in sed:

    \([a-zA-Z]\)\1\1
    

    or in PERL regular expressions

    ([a-zA-Z])\1\1
    
    0 讨论(0)
  • 2020-12-18 06:42

    A regular expression using backreferences would be suitable.

    ([a-z])\1{2}
    

    So something along the lines of preg_match('/([a-z])\1{2}/i', $string); would suffice.

    0 讨论(0)
提交回复
热议问题