質問

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.

役に立ちましたか?

解決

You can use this match:

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

//=> ["#first", "#foo"]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top