Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract Hashtags from String

Let's say I have a paragraph with some hashtags and I want to copy those out and display them separately. Here's some dummy Text:

Visualize how you can e-enable #vertical #architectures? Whenever you can, disintermediate vertical #convergence? #Visualize how you can e-enable #vertical architectures? Whenever you can, disintermediate vertical #convergence?

I'd like to present the hashtags: #convergence, #Visualize, #vertical on my template.

like image 315
Dennis Best Avatar asked Jul 06 '26 21:07

Dennis Best


1 Answers

str = "Visualize how you can e-enable #vertical #architectures?..."
str.scan(/#\w+/).flatten #=> ["#vertical", "#architectures", "#convergence",...]
like image 74
Bala Avatar answered Jul 08 '26 13:07

Bala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!