I made this in C++ and I wanted to convert to JavaScript:
foreach (QString pattern, extensions) {
regex.setPattern(QString("\\.%1").arg(pattern));
regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = regex.match(filename);
if (! match.hasMatch()) continue;
return pattern;
}
It means that foreach extensions
(that is an array of extensions) as pattern
create a pattern with that to be like: \\.png
(for example).
If there's a match it will return the found extension.
I tried to create exactly how I did in C++ but I don't know how to concatenate the returned string from the array to match
const filename = 'example.wutt'
const extensions = ['wutt', 'xnss']
extensions.forEach(pattern => {
const match = filename.match(`\\.${pattern}`)
console.log(match)
})
It does work but it's not case-insensitive as I can't put the i
flag.
How can I do that (and if there's a solution using ES6)?