Batch Convert case in multiple open files (maybe regex?)
-
Let’s say I have 10 text files all open at once, and I want to convert the text in all of those to UPPER CASE. Right now, I have to start in the first file, hit CTRL A, then CTRL-SHIFT-U. File #1 done. Then, I have to click on next file tab, and “rinse & repeat” file by file. I’m looking for a way to change case on these opened files all at once. There’s no such thing as a magical expanded version of CTRL-A, which selects all text in ALL OPENED TEXT FILES? That would be cool, but probably not. Yes, I could macro record the CTRL-A and CTRL-SHIFT-U combo, but I’d still have to go from file to file and run it.
What about some REGEX syntax that would accomplish the same thing? I’m still finding my way with REGEX, so could use syntax examples. Would like to have the syntax for UPPERCASE, lowercase, Proper Case, and Sentence case, if anyone can help. Thx! - Chris -
So you have to do a Replace in Files to do something like this.
Yes, use regex to replace.
with\U$0
.
There are other ways to do it, of course, you could do the find on non-uppercase and only convert those matches, for instance.
I’d say to definitely do a backup on all your files first! -
Alan, tested it, worked perfect! Replacing . with \U$0 (in all files) changed all text to UPPER CASE in one step.
Thank you! I’ve macro’d that and will be using it a lot.
Can I ask for a few more syntaxes?
(1) What would be the Regex to change all to lower case? Would it be replace . with \L$0
(2) … To Proper Case?
(3) … To Sentence case?
(4) Can you briefly verbalize what the syntax means here? Just trying to understand it better.
(5) Here’s the better question I should be asking. I can see the WOW factor and all the potential in learning all this REGEX. I want to learn this stuff. Is there a site you’d recommend as a way to get into understanding REGEX that is NOOB-friendly? I’ve done some coding in the past, but never have tackled regex. Any recommedations? Thx! -
(1) Yep,
\L$0
(2) Search for(\w)(\w+)
and replace with\U${1}\L${2}
(depending up data there may be some limitations)
(3) I don’t think there is going to be a nice equivalent for “sentence case”
(4) Syntax is “match any character” (from the.
) and replace the entire match (from the$0
) with its uppercase equivalent (from the leading\U
)
(5) Great starting info: see the FAQ HERE -
Thanks again! This will save me lots of time (and clicks).
Weird, I’ve been trying to access https://npp-user-manual.org/docs/searching/#regular-expressions, but page keeps timing out. Anyone else? Maybe it’s dead. I’ll poke around some of the other pages referenced on the FAQ
Love notepad++ more each day. -
@Chris-Tanguay-0 said in Batch Convert case in multiple open files (maybe regex?):
I’ve been trying to access https://npp-user-manual.org/docs/searching/#regular-expressions, but page keeps timing out. Anyone else? Maybe it’s dead. I’ll poke around some of the other pages referenced on the FAQ
Very much alive for me.
-
Very much alive for me.
and for me.
@Chris-Tanguay-0 , you might try again – maybe you had a brief network issue. Or maybe you’re using IPv6, which apparently sometimes has issues reaching the online user manual
-
Thanks, all. Just figured out why. I’m at work, and our Sophos firewall says site is hosted from Cyprus. Just had to ask our IT people to unblock. Good times!
-
@Alan-Kilborn I’m having a strange thing going on. I have maybe 8 text files open at same time, not all that long (they are subtitle srt files). I want them all upper case for text. But, when I try replacing . with \U$0 and I choose REPLACE IN ALL FILES, Notepad+ locks up. I let it sit there for a good 2 minutes thinking it was just taking a long time, but nope, I had to crash out of the program. I wonder why it’s having issues with this.
Any thoughts on this, or… maybe some alternate syntax I can try. I’m running on a fairly robust windows 10 machine, so it’s not processing power…
Thanks! -
They may not be huge, but if you’re doing FIND =
.
and REPLACE =\U$0
, then it’s trying to upper-case every byte in the file, even on bytes that are not letters or already uppercase. Sometimes, patience is required: even if it’s only 1Mb, that’s still a million attempts to uppercase the character.Also, you might want to restrict it to only work on lowercase letters, like FIND =
[a-z]+
and the same replacement. -
@PeterJones That (and as you said, a little patience) worked. The [a-z]+ cuts the time in half.
Thanks!