Reputation: 9890
I am trying to create a Regexp in JS that only look into string having files and ignore the paths which don't have a filename.
input
tanxe\src\lib\hello
tanxe\lib\hello\world\verboseBackup.js
tanxe\src\hello\verboseBackup.js
tanxe\lib\verboseBackup.js
Trying
input.match(/^tanxe.*?lib.*?\\..*/i)
Expected Output:
tanxe\lib\hello\world\verboseBackup.js
tanxe\lib\verboseBackup.js
Upvotes: 1
Views: 797
Reputation: 37755
You can try this mate
^.*\.\w+$
Explanation
^
- Anchor to start of string..*
- Matches anything one or more times except newline character.\.
- Matches .
.\w+
- Matches word character one or more time.$
- End of string.Update:- In case you strictly want to match tanxe\lib and followed things only
You can try this mate
^tanxe\\lib\\.+\.\w+$
Upvotes: 2
Reputation: 2292
Try this one too.
tanxe\\[a-zA-Z\\]+[.]{1}[a-zA-z]{2,3}
Upvotes: 1
Reputation: 19154
Your regex is work, I think you need is additional flags: g
global, m
multiline
var input = `tanxe\\src\\lib\\hello
tanxe\\lib\\hello\\world\\verboseBackup.js
tanxe\\src\\hello\\verboseBackup.js
tanxe\\lib\\verboseBackup.js
D:\\Program Files\\atom\\.atom\\packages\\utilities-tanxe\\lib\\abc\\verboseBackup.js`
input.match(/^.*tanxe.*?lib.*?\..*/gmi).forEach(r => console.log(r))
// start with "tanxe"
//input.match(/^tanxe.*?lib.*?\..*/gmi).forEach(r => console.log(r))
Upvotes: 1
Reputation: 12737
input.match(/^tanxe\\lib\\(\w+\\)*\w+\.\w+/gi);
See the regExr fiddle I created.
Upvotes: 1
Reputation: 2587
You might try this: tanxe\\lib.*?\.\w+
It matches paths starting with tanxe\lib
and ending with a file extension.
Upvotes: 1