import re
files = ["index.js", "index.html", "main.js", "foo.js", "bar.js", "foo.something.js", "foo.something1.js", "bar.something.js", "bar.something1.js", "fo.something.js"]
patternjs = r"^.+\.js$"
patternfoo = r"^fo.+\.js$"
patternbar = r"^ba.+\.js$"
patternexcludefoo = r"^foo\.\w+\.js$"
patternexcludebar = r"^bar\.\w+\.js$"
for file in files:
resultfoo = re.match(patternfoo, file)
resultbar = re.match(patternbar, file)
resultjs = re.match(patternjs, file)
resultexcludefoo = re.match(patternexcludefoo, file)
resultexcludebar = re.match(patternexcludebar, file)
if resultfoo or resultbar:
print(file + " is js file either of foo type or bar type")
if resultjs:
print(file + " is js file")
if resultexcludefoo or resultexcludebar:
print(file + " is to be excluded")
As you got the strings, you can manipulate the files accordingly
PS: The code maybe somewhat not upto the mark as I had learned RegEx only 2 days ago. This was the code that I came upto. Didn't checked for JavaScript but these patterns may work as well in JavaScript ( It doesn't support lookbehind and I haven't used it in this code)