matches property

List<RegExpMatch> get matches

Regular expression matches found in the current update.

This property contains a list of RegExpMatch objects that were found when a RegExp filter was applied to any text content in the update. The matches are automatically extracted and stored in the context when using regex patterns with methods like Bot.hears, Bot.callbackQuery, or Bot.inlineQuery.

The text source depends on the method used:

Returns an empty list if no regex filter was applied or no matches were found.

Example:

bot.hears(RegExp(r'\d+'), (ctx) {
  final matches = ctx.matches;
  for (final match in matches) {
    print('Found number: ${match.group(0)}');
  }
});

bot.callbackQuery(RegExp(r'btn_(\w+)'), (ctx) {
  final buttonType = ctx.matches.first.group(1);
  print('Button type: $buttonType');
});

Implementation

List<RegExpMatch> get matches {
  return get('matches') ?? [];
}