Skip to content

Instantly share code, notes, and snippets.

@jtpaasch
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save jtpaasch/9072585 to your computer and use it in GitHub Desktop.

Select an option

Save jtpaasch/9072585 to your computer and use it in GitHub Desktop.
Regex: Alphanumeric, with at least one number and one character
// Match alphanumeric strings, with at least one number and one character.
// -----------------------------------------------------------------------
( // Find a group of:
[0-9]+[a-z] // - one or more digits, followed by a character.
| // - OR
[a-z]+[0-9] // - one or more characters, followed by a digit.
)
[a-z0-9]* // Then, 0 or more digits or characters.
// Match hexadecimal strings, with at least one number and one character.
// ----------------------------------------------------------------------
( // Find a group of:
[0-9]+[a-f] // - one or more digits, followed by a character.
| // - OR
[a-f]+[0-9] // - one or more characters, followed by a digit.
)
[a-f0-9]* // Then, 0 or more digits or characters.
// Match exactly 32 characters.
( // Try to match this group:
?= // Look ahead for:
.* // 0 or more of anything
( // Then:
[a-f]+[0-9] // One or more a-f, followed by one number.
| // OR
[0-9]+[a-f] // One or more 0-9, followed by one character.
)
)
[a-f0-9]{32} // Exactly 32 characters, which are any of a-f or 0-9.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment