snake_case regex pattern

Copy and test a JavaScript regex for snake_case identifiers, with examples and a one-click link to the regex tester.

snake_case regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^[a-z0-9]+(?:_[a-z0-9]+)*$

Flags: -

Search in text

Find matching fragments inside a larger block of text.

Regex: \b[a-z0-9]+(?:_[a-z0-9]+)+\b

Flags: g

Examples that match

  • user_name
  • version_2

Examples that do not match

  • User_Name
  • user-name