extractCurlyBraces method

  1. @useResult
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.

Returns: A list of matched strings (including braces), or null if no matches.

Example:

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

Implementation

@useResult
List<String>? extractCurlyBraces() {
  final List<String> matches = _curlyBracesRegex
      .allMatches(this)
      .map((Match m) => m.group(0))
      .whereType<String>()
      .toList();

  return matches.isEmpty ? null : matches;
}