[英]Split string into multiple substrings starting and ending with special character
I have a string like我有一个像
"i have #newCar and the #noTime in #Days"
and I want to extract words starting with #
:我想提取以#
开头的单词:
a = "#newCar","#noTime',"#Days"
How can I do this?我怎样才能做到这一点?
You can use a regex for this purpose您可以为此使用正则表达式
const s = "i have #newCar and the #noTime in #Days"
const regex = /#[a-zA-Z]+\b/g
console.log(s.match(regex)) // ["#newCar", "#noTime", "#Days"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.