Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to change to sentence case

I'm using Notepad++ to do some text replacement in a 5453-row language file. The format of the file's rows is:

variable.name = Variable Value Over Here, that''s for sure, Really 

Double apostrophe is intentional.

I need to convert the value to sentence case, except for the words "Here" and "Really" which are proper and should remain capitalized. As you can see, the case within the value is typically mixed to begin with.

I've worked on this for a little while. All I've got so far is:

 (. )([A-Z])(.+) 

which seems to at least select the proper strings. The replacement piece is where I'm struggling.

like image 818
jkramp Avatar asked Jun 24 '09 15:06

jkramp


People also ask

How to capitalize regex?

For example, the regular expression "[ A-Za-z] " specifies to match any single uppercase or lowercase letter. In the character set, a hyphen indicates a range of characters, for example [A-Z] will match any one capital letter.

What does \u mean in regex?

U (Unicode dependent), and re. X (verbose), for the entire regular expression. (The flags are described in Module Contents.) This is useful if you wish to include the flags as part of the regular expression, instead of passing a flag argument to the re.

What is b regex?

The metacharacter \b is an anchor like the caret and the dollar sign. It matches at a position that is called a “word boundary”. This match is zero-length. There are three different positions that qualify as word boundaries: Before the first character in the string, if the first character is a word character.


1 Answers

Find:    (. )([A-Z])(.+) Replace: \1\U\2\L\3 

In Notepad++ 6.0 or better (which comes with built-in PCRE support).

like image 199
Jonas Byström Avatar answered Oct 01 '22 01:10

Jonas Byström