ruby - How do I match a UTF-8 encoded hashtag with embedded punctuation characters? -


i want extract #hashtags string, have special characters such #1+1.

currently i'm using:

@hashtags ||= string.scan(/#\w+/) 

but doesn't work special characters. also, want utf-8 compatible.

how do this?

edit:
if last character special character should removed, such #hashtag, #hashtag. #hashtag! #hashtag? etc...

also, hash sign @ beginning should removed.

this should work:

@hashtags = str.scan(/#([[:graph:]]*[[:alnum:]])/).flatten 

or if don't want hashtag start special character:

@hashtags = str.scan(/#((?:[[:alnum:]][[:graph:]]*)?[[:alnum:]])/).flatten 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -