Reputation: 691
I have hashtags in my string. And I can extract the test starting from the # character. But I want to break the extraction at the point where a special character comes.
Example:
String: This is a #first./23k%^ hashtag
Required extract: #first
String: This is another test #hashtag/';123one
Required extract: #hashtag
I did good amount of search on how to do this in JavaScript but I wasn't successful. Kindly help.
Upvotes: 1
Views: 1542
Reputation: 784998
You can use this match:
str="This is a #first./23k%^ hashtag #foo.#$$ 45";
var m = str.match(/#\w+/g);
//=> ["#first", "#foo"]
Upvotes: 8