58

I have a bunch of labels in a text file (e.g. MY LABEL:) that I need to make title case.

I already know how I would make them all lower or upper case.

For example:

^([A-Z &#]+:) to \L$1

However, is there a simple switch-based way to get title case?

Steve
  • 14,401
  • 35
  • 125
  • 230
  • This might help. It covers capializing the first letter of every word http://stackoverflow.com/questions/6251463/regex-capitalize-first-letter-every-word-also-after-a-special-character-like-a – owenrumney Jul 24 '13 at 14:34

2 Answers2

94

Find: ([A-Z])([A-Z]+)\b

Replace: $1\L$2

Make sure case sensitivity is on (Alt + C) and preserve case is off (Alt + A).

garyh
  • 2,782
  • 1
  • 26
  • 28
  • 5
    This worked great, but in RegExBuddy it's `\l` (lowercase L) for whatever reason, if this helps anyone. – degenerate Dec 11 '14 at 19:18
  • 2
    `\L` turns all following characters into lowercase, `\l` only the first following character – Kees de Kooter May 11 '15 at 11:40
  • 3
    Or find `(\w)(\w+)` and replace with `\U$1\L$2` covers all cases, even if words don't start off uppercased. – Riveascore Aug 12 '15 at 19:10
  • 3
    This didn't work for me, but this answer did: http://stackoverflow.com/a/1159389/672989 – Tieme Oct 13 '16 at 13:26
  • 3
    Also, if you want to convert the whole group to uppercase, use `\U$1\E` – М.Б. Jun 29 '17 at 22:34
  • If you want to capitalize: `([a-z])([a-z]+)\b` and then `\u$1$2` – jgthms Apr 09 '18 at 15:38
  • \U and \L replace the entire following text, while \u and \l only replace the first following character. – Lostlinkpr Jun 05 '19 at 02:34
  • The link is broken. When referring to a page off of StackOverflow, it's important to copy and paste the relevent information into your answer so _when_ the link breaks there's some useful information remaining. – the Tin Man Oct 17 '19 at 21:07
25

Have you tried the Sublime Text built in? Edit -> Convert Case -> Title Case.

Edit -> Convert Case -> Title Case

arturomp
  • 28,790
  • 10
  • 43
  • 72
Alexander Wigmore
  • 3,157
  • 4
  • 38
  • 60
  • 1
    Yes, but I was looking for a way to do it with find/replace. I'm sorry, I should have been clearer. – Steve Dec 06 '13 at 14:13
  • 3
    I'd like to note that the built in gives unexpected results (Build 3059). I tested a list of names and email address in the format `first last ,\nfirst last...` and besides the first line, all the first names were left lowercase. – Joel Mellon Jun 04 '14 at 18:37
  • I really like "Smarter Title Case." You can install it through Package Control. I've noticed that it has a few of it's own flaws, but it's 1000 times better than the built in converter. – Pixel Rubble Mar 16 '15 at 17:09
  • This is perfect. I've been looking for that for a long time. – Royi Aug 31 '17 at 04:12