Skip to content

Instantly share code, notes, and snippets.

@isogram
Last active August 29, 2015 14:28
Show Gist options
  • Save isogram/5a4b39d52309031de52d to your computer and use it in GitHub Desktop.
Save isogram/5a4b39d52309031de52d to your computer and use it in GitHub Desktop.
Regex Hashtag
  1. Catch hashtag exclude starting and ending with underscore
    (?:\s|^)(?:#(?!(?:\d+|\w+?_|_\w+?)(?:\s|$)))(\w+)(?=\s|$)
  2. Catch hashtag include starting and ending with underscore
    (?:\s|^)(?:#(?!\d+(?:\s|$)))(\w+)(?=\s|$)
  3. Catch repeating words (only catch 1 if duplicate) (?!.*\b\1\b)

You can test regex at https://regex101.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment