문제

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