healthPattern function

RegExp healthPattern([
  1. List<String> extra = const []
])

The filter as one regex: HEALTH_TERMS plus the app's healthTerms, matched against the lowercased label.

Implementation

RegExp healthPattern([List<String> extra = const []]) {
  final alt = [...HEALTH_TERMS, ...extra]
      .map((t) => t.trim().toLowerCase())
      .where((t) => t.replaceFirst(RegExp(r'\*$'), '').isNotEmpty)
      .map((t) => t.endsWith('*') ? _esc(t.substring(0, t.length - 1)) : '${_esc(t)}(?:e?s)?(?![$_word])');
  return RegExp('(?:^|[^$_word])(?:${alt.join('|')})');
}