Tyvain
Tyvain

Reputation: 2750

Regex Multiline Capitalize all first letter of words and remove space notepad ++

I made this regex demo (working) here: https://regex101.com/r/WSwEbY/6

When I use it in notepad ++, it doesn't work with multiple lines:

hello ladies how are you Today
hello ladies how are you Today

-> result is on a single line:
helloLadiesHowAreYouTodayHelloLadiesHowAreYouToday

Informations:

search: [^\w]+(\w) 
replaceby: \U$1
n++version: 7.5.8

I also try to check 'multiline' or add '$' to en of the search.

Upvotes: 0

Views: 102

Answers (3)

CertainPerformance
CertainPerformance

Reputation: 370699

In addition to not matching newlines in the repeated character set, you should also alternate with a check for if you're at the start of a line - that way the first word on a line will be capitalized as well. Use the m flag so that ^ matches the start of a line:

(?:^|[^\w\n]+)(\w)

Replace with:

\U$1

Output:

HelloLadiesHowAreYouToday
IAmFineThankYou

https://regex101.com/r/dsOcOD/1

Upvotes: 0

TheMaster
TheMaster

Reputation: 50443

How about matching just the space or the start(^) with multiline flag?

(?:^| +)(\w)

sub:

\U$1

Upvotes: 0

Sweeper
Sweeper

Reputation: 271105

Here, you tried to match everything that is not a word character:

[^\w]

However, the new line character \n is also not a word character so it will also be matched by [^\w] and replaced.

You should exclude \n from the character class as well:

[^\w\n]+(\w)

Demo

Upvotes: 1

Related Questions