Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the case of letters in the regular expression in Notepad ++

For example, there is a lot of lines like this: "term - definition". As regular expressions in Notepad ++ can be done to the "term" was written in uppercase (capital) letters - TERM?

Thanks!

like image 277
Доктор Скальпинг Avatar asked Dec 01 '12 14:12

Доктор Скальпинг


People also ask

How do you change capital letters in notepad?

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

How do you change text to lower case?

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 I change all caps to letters in Notepad++?

Change case to Upper CaseHighlight the text and go to menu Edit–>Convert case. Select the Upper case option or use the keyword shortcut (Ctrl+Shift+U) to change the case of the text to upper case in Notepad++ that means all caps.


1 Answers

Find what: ^(\S+)(?=\s*-)
Replace with: \U$1

What does this do? The search pattern matches as many non-space characters at the beginning of a line as possible (\S+) and captures them in variable $1 because of the parentheses. After that follows a lookahead that asserts that this "word" is followed by a hyphen (without anything else in between). This lookahead is not actually included in the match, so it won't be removed/replaced.

The replacement starts with \U which says "output everything after here in upper case unless you stop this with an \E". Then $1 writes back what we matched with \S+ (in your case term). But in upper case.

Make sure to update to Notepad++ 6. Before that regular expressions were a bit quirky.

Here is the documentation of what's possible in the replacement string.

EDIT:

I guess your actual lines might be a bit more interesting than just having one word at the beginning of the line and then the hyphen. But from your given example I can't tell. But to do this for an arbitrary number of words and ignore whitespace at the beginning of the line (as long as there is an hyphen somewhere in the line), you could do something like this:

Find what: ^(([ \t]*[^\s-]+)*)(?=[ \t]*-)

But without actual input examples, I am afraid you have to figure out the proper search pattern yourself.

like image 153
Martin Ender Avatar answered Oct 24 '22 16:10

Martin Ender