TPToolPazar
Ana Sayfa/Rehberler/How To Convert To Snake Case

How To Convert To Snake Case

📖 Bu rehber ToolPazar ekibi tarafından hazırlanmıştır. Tüm araçlarımız ücretsiz ve reklamsızdır.

The four snake variants

snake_case is the naming convention that uses lowercase words joined by underscores. It’s the default for Python functions and variables, Ruby methods, database column names, Rust local variables, and most config files. Converting from other case styles — PascalCase, camelCase, kebab-case, Title Case with Spaces — looks like a one-line regex until you hit acronyms (HTMLParser → html_parser? or h_t_m_l_parser?), numbers embedded in identifiers, and the SCREAMING_SNAKE variant used for constants. This guide covers the canonical conversion rules, how each language’s community treats edge cases, and the regex patterns that produce consistent results.

From camelCase and PascalCase

The canonical rule: insert an underscore before any uppercase letter preceded by a lowercase letter, then lowercase the whole thing.

The acronym problem

“HTMLParser” is a single concept but three capitals in a row. The naive regex turns it into “htmlparser” (missing the word break) or “h_t_m_l_parser” (too aggressive). The canonical fix inserts underscores at two boundaries:

From kebab-case

Trivial substitution:

From Title Case or space-separated

Strip punctuation first for robustness:

Numbers in identifiers

Language communities disagree on how to handle digits next to letters:

SCREAMING_SNAKE_CASE for constants

Convert snake_case to screaming by uppercasing:

Language conventions

Database column naming

Environment variables

Round-trip considerations

Leading-underscore conventions

Common mistakes

Run the numbers