How can we match a^n b^n with Java regex?
问题 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 languge a n b n . Nested references are first introduced in: How does this regex find triangular numbers? One of the archetypal non-regular languages is: L = { a n b n : n > 0 } This is the language of all non-empty strings consisting of some number of a \'s followed by an equal number of b \'s. Examples of strings in this language are ab , aabb