Domanda

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.

È stato utile?

Soluzione

You can use this match:

str="This is a #first./23k%^ hashtag #foo.#$$ 45";
var m = str.match(/#\w+/g);

//=> ["#first", "#foo"]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top