flexAll static method

String flexAll({
  1. required List<String> keywords,
  2. bool searchWords = false,
})

Returns a regex String matching with all the words from the keywords but it does not need to be the perfect word like with all.

Implementation

static String flexAll({
  required List<String> keywords,
  bool searchWords = false,
}) {
  String regex = r'(';

  for (var keyword in keywords) {
    if (searchWords) {
      // The perfect word is in the string.
      keyword = r'\b' + keyword;
    }

    regex += '(?=.*$keyword)';
  }

  return regex + r'.*)';
}