RegExp(pattern) compiles a regular expression from a string. Three common entry points cover most learner cases: hasMatch(text) returns a bool that answers whether the pattern hits anywhere, firstMatch(text) returns the first Match (or null) and m.group(0) reads the whole match, and allMatches(text) returns every match as an Iterable<Match> that can be transformed with the usual map/join.

Program

Play the program to compile r'b\w+', check that it matches cat bat bird, read the first hit, and join every hit with a comma.

regex_basics.dart
void main() {
  var text = 'cat bat bird';
  var pattern = r'b\w+';
  var re = RegExp(pattern);
  var ok = re.hasMatch(text);
  var first = re.firstMatch(text)!.group(0);
  var all = re.allMatches(text).map((m) => m.group(0)).join(',');
  print('$ok $first $all');
}
RegExp `RegExp(pattern)` compiles a regular expression from a string. A raw string `r'...'` keeps backslashes literal, so `b\w+` reads cleanly.
hasMatch and firstMatch `re.hasMatch(text)` returns `bool`. `re.firstMatch(text)` returns the first `Match` (or `null`); `m.group(0)` is the whole match text.
allMatches `re.allMatches(text)` returns every match as an `Iterable<Match>`, so `.map((m) => m.group(0)).join(',')` collects each hit into a comma-separated string.