It seems like this problem would be impossible; I thought that Javascript's regex flavor did not have recursive interpolation or the .NET balancing groups feature. However, on regex.alf.nu, problem 12 is to match balanced pairs of <
and >
. Unless there is some other pattern within the sets that I am missing.
So... is it really possible? If so, how?
NOTES:
I know that this task may seem impossible for true regular expressions, but given the challenge, it appears that it must be achievable using JS flavor (which is irregular enough due to backreferences). I am just not aware of any feature that would enable this.
No additional code - the form only allows entering a single regex, which is then tested against strings on the page. While I could attempt breaking out of the regex into raw JS, it doesn't align with the spirit of this challenge.
Since David inquired about it, here are the test strings. Longer ones have been shortened with a character count, but they all relate to the "Balance" problem title indicating that the "match" column indeed contains balanced pairs of <
and >
, while those in the "not" column do not.
To be matched...
<<<<<>><<>>><<... [62 chars]
<<<<<>><>><<><... [110 chars]
<<<<<>><>><>><... [102 chars]
<<<<<>><>>>><<... [88 chars]
...
...
and unmatched:
<
<<<<<<>>><<><>
... more strings listed ...