Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ Capitalize Every First Letter of Every Word

Input: "notepad++ capitalize every first letter of every word"

Output: "Notepad++ Capitalize Every First Letter Of Every Word"

I have been attempting to capitalize the first letter of every word using ctr+F and regex.

So far I have been attempting to use find:\b(.) or \<(.) with replace:\u\1 but this results in all of my letters being capitalized.

I have made due with ^(.) & \u\1 followed by \s\b(.) & \u\1.

However, this seems silly to me as there are many posts talking about using the start of word boundaries. I am just having difficulty making them work. Thanks for your consideration!

like image 883
Francis Smart Avatar asked Aug 11 '15 21:08

Francis Smart


People also ask

How do you auto capitalize the first letter of every word?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

How do you make the first letter capital in notepad?

Press Ctrl+M (Multirename Tool). In "Uppercase/Lowercase" dropdown select "First of each word uppercase".

How do you capitalize all words in notepad?

You can also use Ctrl+Shift+U for UPPERCASE and Ctrl+U for lowercase if you like shortcut keys.

When you capitalize the first letter of every word?

1. Capitals signal the start of a new sentence. This is a stable rule in our written language: Whenever you begin a sentence capitalize the first letter of the first word. This includes capitalizing the first word or a direct quotation when it's a full sentence, even if it appears within another sentence.


1 Answers

Background

According to Notepad++ specification (see Substitutions section), there are three operators that can be useful when turning substrings uppercase:

\u
Causes next character to output in uppercase
\U
Causes next characters to be output in uppercase, until a \E is found.
\E
Puts an end to forced case mode initiated by \L or \U.

Thus, you can either match a substring and turn its first character uppercase with \u to capitalize it, or match a character and use \U/\E.

Note that Unicode characters won't be turned uppercase, only ASCII letters are affected.


BOW (Beginning of Word) Bug in Notepad++

Note that currently (in Notepad++ v.6.8.8) the beginning of word does not work for some reason. A common solution that works with most engines (use it in Sublime Text and it will match) does not work:

\b(\w)

This regex matches all word characters irrespective of their position in the string.

I logged a bug Word boundary issue with a generic subpattern next to it #1404.


Solution #1 (for the current Notepad++ v.6.8.8)

The first solution can be using the \w+ and replace with \u$0 (no need using any capturing groups). Though this does not mean we only match the characters at the beginning of a word, the pattern will just match chunks of word characters ([a-zA-Z0-9_] + all Unicode letters/digits) and will turn the first character uppercase.


Solution #2 (for the current Notepad++ v.6.8.8)

The second solution can be implemented with special boundaries defined with lookbehinds:

(?:(?<=^)|(?<=\W))\w

And replace with \U$0\E.

The regex (?:(?<=^)|(?<=\W))\w matches an alphanumeric only at the beginning of a line ((?<=^)) or after a non-word character ((?<=\W)).

The replacement - \U$0\E - contains a \U flag that starts turning letters uppercase and \E is a flag that tells Notepad++ to stop converting case.


Edge case

In case you have hyphenated words, like well-known, and you only want the first part to be capitalized, you can use [\w-]+ with \u$0 replacement. It will also keep strings like -v or --help intact.

like image 107
Wiktor Stribiżew Avatar answered Jan 24 '23 21:01

Wiktor Stribiżew