javascript - Regex extension and language -
i looking validating file names. cant figure out correct regex file names can anything, need check if filename ends with
- _ underscore
- en or ru or cy (country code 2 letters)
- . (dot)
- extensions (jpeg, jpg, mp4, png, gif)
so file
my_file_dummy_name.jpeg - not valid my_file_dummy_name_en.jpeg - valid
for tried (and working maybe there better solution)
/(\_\w.\.\w+)/g
one more:
/(\_[a-z]{2}\.[a-z]{3,4})/g
the problem original regex that, while match filenames want allow, match things don't want.
for example, following regex
/(\_\w{2}\.\w+)/g
would match file my_file_dummy_name_de.mpeg
, video file germany. clearly, wouldn't want watch in first place.
try regex:
_(en|ru|cy)\.(jpeg|jpg|mp4|png|gif)$
demo here:
Comments
Post a Comment