any static method
Returns a regex String matching with any word from the keywords
.
Set searchWords
true
for a word search instead of keyword's
characters search.
Implementation
static String any({
required List<String> keywords,
bool searchWords = false,
}) {
String regex = r'(';
for (var keyword in keywords) {
if (searchWords) {
// The word is in the string.
regex += r'\b' + keyword + r'\b';
} else {
// Keyword's characters are in the string.
regex += keyword;
}
if (keyword != keywords.last) {
regex += r'|';
}
}
return regex + r')';
}