GitHub Username
intermediateMatches valid GitHub usernames.
socialgithubusernamevalidation
Pattern
/[a-zA-Z\d](?:[a-zA-Z\d]|-(?=[a-zA-Z\d])){0,38}/gTry It
0 of 6 strings matched
Explanation
Matches GitHub usernames: starts with alphanumeric, allows hyphens (but not consecutive or trailing), max 39 characters. Uses a lookahead to prevent trailing hyphens.
Test Strings
Matching
- octocat
- user-name
- a1b2c3
Non-matching
- ---
- ...
Language Compatibility
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Not supported (RE2 engine) |
Code Snippets
const regex = /[a-zA-Z\d](?:[a-zA-Z\d]|-(?=[a-zA-Z\d])){0,38}/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);