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

  1. _ underscore
  2. en or ru or cy (country code 2 letters)
  3. . (dot)
  4. 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:

regex101


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -