group abstract method

String? group(
  1. int group
)

The string matched by the given group.

If group is 0, returns the entire match of the pattern.

The result may be null if the pattern didn't assign a value to it as part of this match.


final string = '[00:13.37] This is a chat message.';
final regExp = RegExp(r'^\[\s*(\d+):(\d+)\.(\d+)\]\s*(.*)$');
final match = regExp.firstMatch(string)!;
final message = jsonEncode(match.group(0)!); // '[00:13.37] This is a chat message.'
final hours = jsonEncode(match.group(1)!); // '00'
final minutes = jsonEncode(match.group(2)!); // '13'
final seconds = jsonEncode(match.group(3)!); // '37'
final text = jsonEncode(match.group(4)!); // 'This is a chat message.'

Implementation

String? group(int group);