-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractFileName.js
More file actions
26 lines (21 loc) · 824 Bytes
/
Copy pathextractFileName.js
File metadata and controls
26 lines (21 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* You have to extract a portion of the file name as follows:
Assume it will start with date represented as long number
Followed by an underscore
Youll have then a filename with an extension
it will always have an extra extension at the end
Inputs:
1231231223123131_FILE_NAME.EXTENSION.OTHEREXTENSION
1_This_is_an_otherExample.mpg.OTHEREXTENSIONadasdassdassds34
1231231223123131_myFile.tar.gz2
Outputs:
FILE_NAME.EXTENSION
This_is_an_otherExample.mpg
myFile.tar
Acceptable characters for random tests:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-0123456789
The recommend way to solve it is using RegEx and specifically groups. */
class FileNameExtractor {
static extractFileName (dirtyFileName) {
return dirtyFileName.substring(dirtyFileName.indexOf("_")+1, dirtyFileName.lastIndexOf("."))
}
}