使用正则表达式匹配 Dart 语言中的特定字符串

match specific string in Dart Language with Regex

我正在寻找 Dart 的 Regex 公式,以检查输入是否匹配我证明的特定字符串。示例:输入为'butter',证明字符串为['but','burst','bus']。该程序应该 return false 因为 'but' 不等于 'butter'。但它是 returning true 如下代码。

void main() {
  const string = 'Can you give me a butter';
  const pattern = r'(but)|(burst)|(bus)';
  final regExp = RegExp(pattern);
  print(regExp.hasMatch(string.toLowerCase())); //true
}

当我如下更改代码时,效果很好。

void main() {
  const string = 'Can you give me a But asasa';
  const pattern = r'\b(but|burst|bus)\b';
  final regExp = RegExp(pattern, caseSensitive: false);
  print(regExp.hasMatch(string)); 
}