๐Ÿ“š General & Other

Splitting Words Is the Hard Part of snake_case

Converting to snakecase requires knowing where the words are, and the input rarely tells you unambiguously.

Converting to snake_case requires knowing where the words are, and the input rarely tells you unambiguously.

From camelCase, mostly mechanical

Insert an underscore before each uppercase letter and lowercase everything. pageLoadTime becomes pageloadtime correctly. Acronyms break it: parseHTTPResponse becomes parsehttp_response unless the rule handles runs of capitals as a unit.

The usual fix inserts a boundary before a capital only when it follows a lowercase letter, or when it is followed by a lowercase letter. That handles HTTPResponse correctly as http_response.

Digits are ambiguous

Is utf8Encode two words or three? address2 or address_2? No rule satisfies everyone, and different libraries choose differently โ€” which is why converting through two libraries can produce two different column names for the same field.

Leading and trailing separators

Input with spaces at the ends produces fieldname_, which is a legal but unintended identifier. Trim before converting, and collapse consecutive separators afterwards.

Try it: Convert to snake_case on SeoWolf's Notepad.