Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strip hashtags from string using JavaScript

I have a string that may contains Twitter hashtags. I'd like to strip it from the string. How should I do this? I'm trying to use the RegExp class but it doesn't seem to work. What am I doing wrong?

This is my code:

var regexp = new RegExp('\b#\w\w+');
postText = postText.replace(regexp, '');
like image 312
Vitor Py Avatar asked Aug 18 '10 16:08

Vitor Py


1 Answers

This?

postText = "this is a #bla and a #bla plus#bla"
var regexp = /\#\w\w+\s?/g
postText = postText.replace(regexp, '');
console.log(postText)
like image 85
mplungjan Avatar answered Sep 20 '22 19:09

mplungjan