Repository: symfony/symfony
File: src/Symfony/Component/OptionsResolver/OptionsResolver.php (PHP)

Code before:
     * @return list<string>
     */
    private function splitOutsideParenthesis(string $type): array
    {
        return preg_split(<<<'EOF'
                /
                # Match a balanced parenthetical group, then skip it.
                \(              # Match an opening parenthesis.
                [^()]*          # Match any non-parenthesis characters.
                (?:             # Start a non-capturing group for nested parts.
                    \([^()]*\)  # Match a simple, non-nested (...) group.
                    [^()]*      # Match any non-parenthesis characters that follow it.
                )*              # Repeat this group zero or more times to handle multiple nested groups.
                \)              # Match the final closing parenthesis.

                (*SKIP)(*FAIL)  # Discard the entire match and force the engine to find the next match.

                | # OR

                \| # Match the pipe delimiter. This will only be matched if it was not inside a skipped group.
                /x
        EOF, $type);
    }

    /**
     * Returns whether a resolved option with the given name exists.
     *
     * @throws AccessException If accessing this method outside of {@link resolve()}
     *
     * @see \ArrayAccess::offsetExists()
     */
    public function offsetExists(mixed $option): bool
    {
        if (!$this->locked) {
            throw new AccessException('Array access is only supported within closures of lazy options and normalizers.');
        }

        return \array_key_exists($option, $this->defaults);
    }

    /**
     * Not supported.
     *
     * @throws AccessException
     */
    public function offsetSet(mixed $option, mixed $value): void
    {
        throw new AccessException('Setting options via array access is not supported. Use setDefault() instead.');
    }

    /**

Review comment (bug):
can you try using a recursive regexp? this will remove the current limitation of parsing only the first 2 levels of nesting:
```
/
  # Match a recursively balanced parenthetical group, then skip it
  \(              # Match an opening parenthesis
  (?:             # Start a non-capturing group for the contents
      [^()]       # Match any character that is not a parenthesis
    |             # OR
      (?R)        # Recurse the entire pattern to match a nested group
  )*              # Repeat the group for all contents
  \)              # Match the final closing parenthesis
  (*SKIP)(*FAIL)  # Discard the match and find the next one
| # OR
  \|              # Match the pipe delimiter (only if not inside a skipped group)
/x
```

Code after:
     * @return list<string>
     */
    private function splitOutsideParenthesis(string $type): array
    {
        return preg_split(<<<'EOF'
                /
                # Define a recursive subroutine for matching balanced parentheses
                (?(DEFINE)
                    (?<balanced>
                        \(                          # Match an opening parenthesis
                        (?:                         # Start a non-capturing group for the contents
                            [^()]                   # Match any character that is not a parenthesis
                            |                       # OR
                            (?&balanced)            # Recursively match a nested balanced group
                        )*                          # Repeat the group for all contents
                        \)                          # Match the final closing parenthesis
                    )
                )

                # Match any balanced parenthetical group, then skip it
                (?&balanced)(*SKIP)(*FAIL)          # Use the defined subroutine and discard the match

                | # OR

                \|                                  # Match the pipe delimiter (only if not inside a skipped group)
                /x
        EOF, $type);
    }

    /**
     * Returns whether a resolved option with the given name exists.
     *
     * @throws AccessException If accessing this method outside of {@link resolve()}
     *
     * @see \ArrayAccess::offsetExists()
     */
    public function offsetExists(mixed $option): bool
    {
        if (!$this->locked) {
            throw new AccessException('Array access is only supported within closures of lazy options and normalizers.');
        }

        return \array_key_exists($option, $this->defaults);
    }

    /**
     * Not supported.
     *
     * @throws AccessException
     */
    public function offsetSet(mixed $option, mixed $value): void