How can we match a^n b^n with Java regex?

前端 未结 3 1719
忘了有多久
忘了有多久 2020-11-22 15:06

This is the second part of a series of educational regex articles. It shows how lookaheads and nested references can be used to match the non-regular

3条回答
  •  执笔经年
    2020-11-22 15:18

    Given that no mention has been made of PCRE supporting recursive patterns, I'd just like to point out the simplest and most efficient example of PCRE that describes the language in question:

    /^(a(?1)?b)$/
    

提交回复
热议问题