Reg expression to change characters within brackets '[ ]' to uppercase?
-
Hi,
I’m having trouble coming up with a reg expression for the replace option for the following scenario:Would like to replace all lowercase characters with brackets to uppercase.
i.e. array[enum1_name] becomes array[ENUM1_NAME].
I’ll defer to the reg expression experts out there.
Thanks!
-
Find what:
\[([^]]*)\]
Replace With:[\U$1\E]Finds everything between
[and], inclusive, saving the stuff between the brackets as$1
The\Uand\Esay to make everything between those two escapes uppercase. Thus\U$1\Euppercases everything in$1.EDIT: that assumes you don’t have nested brackets, like
outer[ inner[ ENUM_HERE ] ]. If you do, you’ll have to define some rules for what’s allowed and what isn’t, and what needs capitalizing and what doesn’t. -
Thanks so much! Worked like a champ! Over 750 replacements in one file alone. What a time saver.
-
Hi, @kurt-ehrhardt, @Peterjones and All
Ah, already solved, nice :-)) So, just for fun, an other formulation could be :
SEARCH
\[.*?\]REPLACE
\U$0Note, Kurt, that the two search regexes, from Peter and me, would match a “multi-lines” square-bracket block, too, as, for instance :
array[ENUM1 _NAME]Thus, to restrict to a single-line square-bracket block, the Peter’s search regex should be changed into :
SEARCH
\[([^]\r\n]*)\]And mine should be written :
SEARCH
(?-s)\[.*?\]Cheers,
guy038
P.S. :
Note that replacement case operations occur, only, with classical letters in range
[A-Za-z]Unfortunately, for Non English-American people, this does not work, at all, for accentuated letters :-((
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login