This library seems really cool: according to the docs, it manages to detect some complicated patterns.
I haven't used it yet, but I'll give it a try in my future projects.
And according to bundlephobia, it's only 1.6kB minified and gzipped so I think I'll use it as a building block for all my future pattern match!