0

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.

3
  • I tried many options but didnt worked out, please share Commented Mar 20, 2020 at 18:38
  • @LawrenceCherone smoke_\s*(\+\d+). As I said I am very new to regex. so I am not sure. Commented Mar 20, 2020 at 18:40
  • cool, /smoke_(\d+)-/gm for number or (smoke_(\d+))- for inc smoke_ Commented Mar 20, 2020 at 18:44

2 Answers 2

1

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)
})

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.