Code: Regex for Instagram Username and Hashtags

Instagram is unique when it comes to the rules for usernames and hashtags. Here is a regex to capture and validating them with the JavaScript regex engine.

The rules

  • Two matches @ mentions with no space between @thebox193@discodude
  • Matches with one . in them @disco.dude but not two .. @disco..dude
  • Beginning period not matched @.discodude
  • Ending period not matched @discodude.
  • Match underscores _ @_disco__dude_
  • Max characters of 30 @1234567890123456789012345678901234567890

The RegEx

Instagram username RegEx


For hashtags use the same regex, it’s the same rules, just replace the @ for a #.



You can try it out over on Debuggex. Here is a an example implemented in JavaScript.