I am using this:
if (data.match(/([^\/\\]+ )\.(txt|doc)$/i) )
return {filename: RegExp.$1, ext: RegExp.$2};
to only allow (when true) file .ext’s that are listed. Which, for the above is txt and doc. This works well until it comes accross a filename that is just an extension Such as .DS_store. If e.g., .DS_store is encountered it stops testing. How can the statement be modified to gracefully reject filenames that only consists of the ext, while continuing to process other filenames?
Thanks
Try this: (will not match “.doc”, nor ” .doc”, but will parse: ‘myfile/Regular name.doc’):
(you gobble up leading spaces, but your situation is complicated by the fact that spaces are valid in the name. But since you can’t use possessive quantifiers, you mimic this behavior with a positive look-ahead zero-width assertion that includes zero, then a back-reference to that.)