Reputation: 2292
I have strings -
[ '/home/user/Music/test/project/iit/feature/ABC/release1/PC/en_smoke/smoke_01-login.feature' ]
[ '/home/user/Music/test/project/iit/feature/ABC/release1/PC/en_smoke/smoke_02-logout.feature' ]
[ '/home/user/Music/test/project/iit/feature/ABC/release1/PC/en_smoke/smoke_03-createaccount.feature' ]
I need to extract the string the string "smoke_xx"
so whatever the number comes along with smoke_, I need to extract it. I tried many options but didnt worked out. I am new to nodejs. Please help.
Upvotes: 0
Views: 110
Reputation: 302
It will work with following regex:
(?i)\bsmoke\s*_\s*\d+
you can check the link to view result: https://regex101.com/r/z8uUTf/2
Upvotes: 1
Reputation: 5703
with regex of @Lawrence Cherone and use of String.prototype.match
[
'/home/user/Music/test/project/iit/feature/ABC/release1/PC/en_smoke/smoke_01-login.feature',
'/home/user/Music/test/project/iit/feature/ABC/release1/PC/en_smoke/smoke_02-logout.feature',
'/home/user/Music/test/project/iit/feature/ABC/release1/PC/en_smoke/smoke_03-createaccount.feature'
].forEach(path => {
const smoke = path.match(/smoke_\d+/)[0]
console.log('smoke :', smoke)
})
Upvotes: 1