Created
March 17, 2014 16:30
-
-
Save taylor-smith/9602794 to your computer and use it in GitHub Desktop.
Ruby regex to match hashtags in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http://www.rubular.com/r/PySQB8NvUY | |
(?:\s|^)(?:#(?!(?:\d+|\w+?_|_\w+?)(?:\s|$)))(\w+)(?=\s|$) | |
Test String: | |
#blah Pack my #box with #5 dozen #good2 #3good liquor.#jugs link.com/liquor#jugs #mkvef214asdwq sd #3e4 flsd #2good #_hello and #hello_ , how to just allow #hello2_world or #hello_23 #first#second #3 | |
Match 1 | |
1. blah | |
Match 2 | |
1. box | |
Match 3 | |
1. good2 | |
Match 4 | |
1. 3good | |
Match 5 | |
1. mkvef214asdwq | |
Match 6 | |
1. 3e4 | |
Match 7 | |
1. 2good | |
Match 8 | |
1. hello2_world | |
Match 9 | |
1. hello_23 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment