How to extract parts of a filename using RegExp?
I don't use RegExp often, but in most cases I can handle it.
Now I have a list of filenames from cameras in the format
_MG_4991.cr2
DSC_0986.JPG
etc., in this case, between the digital index and the file extension there can be arbitrary characters (as a rule, the photographer's comments)
I want to parse these names into parts so that I get a separate prefix specific to the camera (for example, _MG_ or DSC_ or NEF_), the numerical value of the frame number and the file extension. At the same time, I need to ignore the comment of the photographer.
I read the RegExp documentation for a long time and ended up doing this:
var init = decodeURI(etTarget.path[i].name).match(new RegExp('([\D]*)(\d+)[\D]*(\.[\D]*)'))
(where etTarget.path [i] is an element of an array of objects of the File type). But it doesn't work.
I hope there are people here who are more advanced in working with strings and I will get an answer 🙂
