extractCurlyBraces method

List<String>? extractCurlyBraces()

Extracts all text within curly braces from this string.

Uses a non-greedy regex ({.+?}) to match multiple brace-enclosed groups in the order they appear. Adjacent groups like {a}{b} are correctly separated.

Limitation: Does not handle nested braces. For {a{b}c}, only {a{b} may match.

Returns: A list of matched strings (including braces), or null if no matches found. The list preserves the order of matches in the original string.

Example:

'{start} middle {end}'.extractCurlyBraces(); // ['{start}', '{end}']
'{a}{b}{c}'.extractCurlyBraces(); // ['{a}', '{b}', '{c}']
'{你好}'.extractCurlyBraces(); // ['{你好}'] (Unicode supported)
'no braces'.extractCurlyBraces(); // null

Implementation

List<String>? extractCurlyBraces() {
  final List<String> matches = _curlyBracesRegex
      .allMatches(this)
      .map((Match m) => m[0])
      .whereType<String>()
      .toList();
  return matches.isEmpty ? null : matches;
}