0

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 ?

React_Coder
  • 353
  • 2
  • 12

1 Answers1

1

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"]
Tayyab Mazhar
  • 1,560
  • 10
  • 26