Yeah well that’s regular expressions. ¯\_(ツ)_/¯
Maybe a bit off-topic, but there’s a neat library called Super Expressive that makes working with these a bit easier; the above expression would then look something like this:
const SuperExpressive = require('super-expressive')
const regex = SuperExpressive()
.wordBoundary
.capture
.anyOf
.string('apple')
.string('bee')
.end()
.end()
.zeroOrMore.nonWhitespaceChar
.allowMultipleMatches
.caseInsensitive
.toRegex()
const input = 'the beer drinking bee does not l!ke apple-cider'
console.log([...input.matchAll(regex)])