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.

Can I use camelCase in CSS class names

Technically yes, but it’s risky because while CSS syntax is mostly case-insensitive, in some browsers under certain conditions, class names are treated as case-sensitive, as the spec does not specify how browsers should handle case when matching CSS rules to HTML class names. From the spec, section 4.1.3: All CSS syntax is case-insensitive within the … Read more

linux bash, camel case string to separate by dash

You can use s/\([A-Z]\)/-\L\1/g to find an upper case letter and replace it with a dash and it’s lower case. However, this gives you a dash at the beginning of the line, so you need another sed expression to handle that. This should work: sed –expression ‘s/\([A-Z]\)/-\L\1/g’ \ –expression ‘s/^-//’ \ <<< “MyDirectoryFileLine”

How to do CamelCase split in python

As @AplusKminus has explained, re.split() never splits on an empty pattern match. Therefore, instead of splitting, you should try finding the components you are interested in. Here is a solution using re.finditer() that emulates splitting: def camel_case_split(identifier): matches = finditer(‘.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)’, identifier) return [m.group(0) for m in matches]

Force CamelCase on ASP.NET WebAPI Per Controller

Thanks to @KiranChalla I was able to achieve this easier than I thought. Here is the pretty simple class I created: using System; using System.Linq; using System.Web.Http.Controllers; using System.Net.Http.Formatting; using Newtonsoft.Json.Serialization; public class CamelCaseControllerConfigAttribute : Attribute, IControllerConfiguration { public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) { var formatter = controllerSettings.Formatters.OfType<JsonMediaTypeFormatter>().Single(); controllerSettings.Formatters.Remove(formatter); formatter = new JsonMediaTypeFormatter { … Read more

Acronyms in CamelCase [closed]

There are legitimate criticisms of the Microsoft advice from the accepted answer. Inconsistent treatment of acronyms/initialisms depending on number of characters: playerID vs playerId vs playerIdentifier. The question of whether two-letter acronyms should still be capitalized if they appear at the start of the identifier: USTaxes vs usTaxes Difficulty in distinguishing multiple acronyms: i.e. USID … Read more

How can I return camelCase JSON serialized by JSON.NET from ASP.NET MVC controller methods?

or, simply put: JsonConvert.SerializeObject( <YOUR OBJECT>, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); For instance: return new ContentResult { ContentType = “application/json”, Content = JsonConvert.SerializeObject(new { content = result, rows = dto }, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }), ContentEncoding = Encoding.UTF8 };

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

RegEx to split camelCase or TitleCase (advanced)

The following regex works for all of the above examples: public static void main(String[] args) { for (String w : “camelValue”.split(“(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])”)) { System.out.println(w); } } It works by forcing the negative lookbehind to not only ignore matches at the start of the string, but to also ignore matches where a capital letter is preceded by … Read more