duanjiao8871 2012-10-31 04:50
浏览 66
已采纳

Php正则表达式preg_match重复字符

I have a string in php like this.

$string = "123451" 

which contains non-consecutive repeated characters of 1. How do i match the repeated characters using preg_match.

I browsed around and found preg_match('/(.)\1\1/', $string)) but it only works for repeated consecutive characters.

  • 写回答

1条回答 默认 最新

  • dongshi3605 2012-10-31 05:41
    关注

    What about something like

    (\d+).*\1
    

    If you get any match there is a repeated number.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?