Snake case
FormatExperimentalLimited support. Verify anything critical.
Snake case is a text formatting convention that splits phrases on spaces, hyphens, and capital-letter boundaries, then lowercases every token and joins them together with underscores (e.g., my_variable_name). Our snake case converter runs entirely locally within your browser, ensuring strict privacy. All text transformation happens directly on your device, meaning your data is never uploaded, stored, or sent to any external processing server.
This tool processes text on your device. The text is not uploaded.
How to use Snake case
What is Snake case?
Snake case is a text formatting convention that splits phrases on spaces, hyphens, and capital-letter boundaries, then lowercases every token and joins them together with underscores (e.g., my_variable_name). Our snake case converter runs entirely locally within your browser, ensuring strict privacy. All text transformation happens directly on your device, meaning your data is never uploaded, stored, or sent to any external processing server.
Tokenization and conversion algorithm
To accurately convert arbitrary strings into snake_case, the tool follows a reliable algorithm:
- Boundary detection: The input string is analyzed to find boundaries. This includes explicit separators like spaces, hyphens (
-), and existing underscores (_), as well as implicit boundaries like camelCase transitions (where a lowercase letter is immediately followed by an uppercase letter). - Case normalization: Every identified token is converted to lowercase.
- Concatenation: The normalized tokens are joined back together using standard underscores without any surrounding spaces.
Practical developer use cases
Snake case is highly prevalent in software engineering and system administration. Some common use cases include:
- Relational database schemas: Defining SQL tables, columns, and foreign keys (e.g.,
customer_id,billing_address,created_at). Snake case ensures excellent cross-platform compatibility and readability in SQL dialects. - Python programming: Standardizing variable definitions and function signatures according to the PEP 8 Style Guide for Python Code.
- Rust programming: Adhering to idiomatic Rust naming conventions for module names, variables, and function definitions.
- File and directory naming: Organizing assets in Linux-based POSIX filesystems to avoid the complexities that whitespace can introduce in bash scripts and command-line operations.
Best practices and considerations
When using snake_case, consider the following best practices:
- Screaming snake case: For global constants, environment variables, or immutable configuration values, you should use screaming snake case (e.g.,
MAX_RETRY_COUNT). This is simply an all-uppercase variant of standard snake case. - Acronym handling: The tokenizer handles acronyms by splitting boundaries carefully. For example, a string like ‘parseHTMLResponse’ is transformed into ‘parse_html_response’ to maintain a consistent output structure.
- Internationalization: While this tool retains base Unicode characters and lowercases them, it does not perform ASCII transliteration. Keep this in mind if you are generating programmatic identifiers for systems that strictly require ASCII characters.
Code examples
Here is how you can implement snake case conversion in various programming languages:
JavaScript / TypeScript
function toSnakeCase(input: string): string {
return input
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
.replace(/[-\s]+/g, "_")
.trim()
.toLowerCase()
.replace(/_+/g, "_");
}Python 3
import re
def to_snake_case(text: str) -> str:
words = re.sub(r"[-_]+", " ", re.sub(r"([a-z0-9])([A-Z])", r"\1 \2", text)).split()
return "_".join(word.lower() for word in words)How it works
- Enter what you haveType or pick your text. Nothing is submitted anywhere.
- It runs in this tabThe calculation happens on your device, using your browser's own data.
- Take the resultRead the text, then copy, download, or share a link.
Reimplemented locally. Not derived from IT-Tools source.
- Basis
- independent
- Licence
- MIT
- Last reviewed
Frequently asked questions
What is screaming-snake-case (SCREAMING_SNAKE_CASE)?
Screaming snake case is an all-uppercase variant of snake_case commonly used in programming to denote global constants, environment variables, or immutable configuration values.
How does the tokenizer handle uppercase sequences and acronyms?
The transformation safely splits acronym boundaries (e.g. 'parseHTMLResponse' -> 'parse_html_response' or 'parse_htmlresponse'), ensuring consistent lowercase underscored output.
Are international characters and accents preserved?
Snake_case retains base Unicode characters but lowercases them. It does not perform ASCII transliteration.