Skip to content

All articles

Convert camelCase to snake_case: tested examples

By FlipMyCase · Published · Reviewed

To convert camelCase to snake_case, separate the words before lowercasing them: customerId becomes customer_id. FlipMyCase also separates an acronym from a following word, so HTTPServer becomes http_server. Always review the result before renaming anything in a codebase.

Try the case converter

How do I convert an existing identifier?

Paste one identifier into the case converter. All outputs appear together; copy the snake_case card to use underscores, or choose camelCase, PascalCase, kebab-case, CONSTANT_CASE or dot.case for another format. Separate words with spaces if the intended boundaries are ambiguous.

The identifier formats split an ASCII lowercase letter or digit followed by an uppercase letter. They also split a run of uppercase letters before an uppercase letter that starts a lowercase word. Existing spaces, underscores, hyphens and other non-ASCII-alphanumeric characters separate tokens. Casing is applied after this split. The examples table shows the resulting behavior, including its limitations.

What happens to acronyms and numbers?

HTTPServer has enough casing information to identify HTTP and Server. XMLHTTP does not indicate where one acronym ends, so it becomes xmlhttp. If you mean XML and HTTP as separate words, enter XML HTTP instead. A converter cannot reliably recover boundaries that are absent from the input.

Digits stay attached to the preceding token; a following uppercase letter begins another token. Thus version2Value becomes version2_value. This is a formatting choice in this tool, not a universal naming convention. Check your project's examples and linter rules before applying it.

Does snake_case make an identifier valid Python?

No. PEP 8 recommends lowercase function and variable names, with underscores between words as needed for readability. It is style guidance, not proof that any converted string is a valid identifier. The converter can output 123_name, which starts with digits, or class, which is a Python keyword. Neither is suitable as an ordinary Python variable name.

The formatter uses ASCII letters and digits for these identifier formats. Accented letters and other scripts are not preserved as identifier tokens: caféName becomes caf_name, and an input containing only Chinese characters produces an empty result. Preserve the original text and use language-aware tools when your project needs Unicode identifiers. Uppercase and lowercase text conversion are separate functions and have different behavior.

How do I rename a variable without breaking references?

Use the converter to decide on the spelling, then use your editor's language-aware rename operation to change the symbol. Inspect the diff and run your project's tests. A text formatter does not understand scope, imports, database migrations, serialized field names or external API consumers.

Avoid a global text replacement when the same spelling can refer to unrelated symbols. A public API key or database column can require a compatibility plan even when its new spelling follows your preferred style. Formatting a name and safely migrating an interface are different tasks.

Tested input and output

Examples checked against the case converter. An empty result is labeled explicitly.
FormatInputOutput
snake-casecustomerIdcustomer_id
snake-caseHTTPServerhttp_server
snake-caseversion2Valueversion2_value
camel-casecustomer_idcustomerId
pascal-caseHTTP_serverHttpServer
constant-caseapiResponseAPI_RESPONSE
snake-caseXMLHTTPxmlhttp
snake-caseXML HTTPxml_http
snake-case123Name123_name
snake-casecaféNamecaf_name
snake-case中文(empty result)

Sources and review

Prepared with AI assistance. The examples below are checked against FlipMyCase's conversion functions by automated regression tests. External naming guidance was checked against PEP 8. This review does not validate every programming language or identifier.

Editorial policy · Report a correction