Regex for PascalCased words (aka camelCased with leading uppercase letter)

([A-Z][a-z0-9]+)+ Assuming English. Use appropriate character classes if you want it internationalizable. This will match words such as “This”. If you want to only match words with at least two capitals, just use ([A-Z][a-z0-9]+){2,} UPDATE: As I mentioned in a comment, a better version is: [A-Z]([A-Z0-9]*[a-z][a-z0-9]*[A-Z]|[a-z0-9]*[A-Z][A-Z0-9]*[a-z])[A-Za-z0-9]* It matches strings that start with an uppercase letter, … Read more

What is the naming convention in Python for variables and functions?

See Python PEP 8: Function and Variable Names: Function names should be lowercase, with words separated by underscores as necessary to improve readability. Variable names follow the same convention as function names. mixedCase is allowed only in contexts where that’s already the prevailing style (e.g. threading.py), to retain backwards compatibility.

Built-in function to capitalise the first letter of each word

SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[InitCap] ( @InputString varchar(4000) ) RETURNS VARCHAR(4000) AS BEGIN DECLARE @Index INT DECLARE @Char CHAR(1) DECLARE @PrevChar CHAR(1) DECLARE @OutputString VARCHAR(4000) SET @OutputString = LOWER(@InputString) SET @Index = 1 WHILE @Index <= LEN(@InputString) BEGIN SET @Char = SUBSTRING(@InputString, @Index, 1) SET @PrevChar = CASE WHEN … Read more

How to convert PascalCase to snake_case?

A shorter solution: Similar to the editor’s one with a simplified regular expression and fixing the “trailing-underscore” problem: $output = strtolower(preg_replace(‘/(?<!^)[A-Z]/’, ‘_$0’, $input)); PHP Demo | Regex Demo Note that cases like SimpleXML will be converted to simple_x_m_l using the above solution. That can also be considered a wrong usage of camel case notation (correct … Read more

How do I convert CamelCase into human-readable names in Java?

This works with your testcases: static String splitCamelCase(String s) { return s.replaceAll( String.format(“%s|%s|%s”, “(?<=[A-Z])(?=[A-Z][a-z])”, “(?<=[^A-Z])(?=[A-Z])”, “(?<=[A-Za-z])(?=[^A-Za-z])” ), ” ” ); } Here’s a test harness: String[] tests = { “lowercase”, // [lowercase] “Class”, // [Class] “MyClass”, // [My Class] “HTML”, // [HTML] “PDFLoader”, // [PDF Loader] “AString”, // [A String] “SimpleXMLParser”, // [Simple XML Parser] … Read more

JSON Naming Convention (snake_case, camelCase or PascalCase) [closed]

In this document Google JSON Style Guide (recommendations for building JSON APIs at Google), It recommends that: Property names must be camelCased, ASCII strings. The first character must be a letter, an underscore (_), or a dollar sign ($). Example: { “thisPropertyIsAnIdentifier”: “identifier value” } My team consistently follows this convention when building REST APIs. … Read more

.NET – How can you split a “caps” delimited string into an array?

I made this a while ago. It matches each component of a CamelCase name. /([A-Z]+(?=$|[A-Z][a-z])|[A-Z]?[a-z]+)/g For example: “SimpleHTTPServer” => [“Simple”, “HTTP”, “Server”] “camelCase” => [“camel”, “Case”] To convert that to just insert spaces between the words: Regex.Replace(s, “([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))”, “$1 “) If you need to handle digits: /([A-Z]+(?=$|[A-Z][a-z]|[0-9])|[A-Z]?[a-z]+|[0-9]+)/g Regex.Replace(s,”([a-z](?=[A-Z]|[0-9])|[A-Z](?=[A-Z][a-z]|[0-9])|[0-9](?=[^0-9]))”,”$1 “)