Why will this recursive regex only match when a character repeats 2^n - 1 times?

前端 未结 2 1164
南旧
南旧 2021-01-05 15:13

After reading polygenelubricants\'s series of articles on advanced regular expressions techniques (particularly How does this Java regex detect palindromes?), I decided to a

2条回答
  •  轮回少年
    2021-01-05 15:57

    In case you would like a fully functional PCRE expression to match palindromes, you can use the following:

    /^(?:(.)(?=.*(\1(?(2)\2))$))*+.?\2?$/

提交回复
热议问题