[英]How to extract a particular string from the given string in nodejs
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.我需要提取字符串
"smoke_xx"
所以无论smoke_ 附带的数字是什么,我都需要提取它。 I tried many options but didnt worked out.我尝试了很多选择,但没有成功。 I am new to nodejs.
我是 nodejs 的新手。 Please help.
请帮忙。
with regex of @Lawrence Cherone and use of String.prototype.match使用@Lawrence Cherone 的正则表达式并使用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) })
它适用于以下正则表达式: (?i)\\bsmoke\\s*_\\s*\\d+
您可以查看链接以查看结果: https : //regex101.com/r/z8uUTf/2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.