79658126

Date: 2025-06-08 19:37:50
Score: 0.5
Natty:
Report link

This is a famous challenge from TJCTF 2025, it is solvable using advanced regex engines like PCRE (Perl Compatible Regular Expressions) — used in languages like Perl, PHP, or the regex module in Python.

One such solution (credits to @cinabun):
^(.)(\1|(.)(?=.*$(?<=^((?!\1|\3).|\1(?4)*?\3|\3(?4)*?\1)*)))*$

This complex regex is designed to validate strings containing perfectly balanced pairs of two distinct delimiters, which are dynamically identified as the first character (opening) and the first different character (closing) in the string. It uses capturing groups, backreferences, lookaheads, lookbehinds, and recursion to enforce this structure.

Group 1 captures the opening delimiter, and Group 3 captures the closing delimiter, but only if the remaining string can be parsed into a valid sequence of balanced delimiter pairs or content characters that are neither.

The recursion ((?4)) enables checking for nested structures, while lookahead and lookbehind ensure the entire string can be decomposed into these balanced segments.

This allows the regex to verify arbitrarily nested and interleaved structures using just two characters as delimiters, ensuring every opening has a corresponding closing and vice versa.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @cinabun
  • Low reputation (1):
Posted by: p sin