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.


  • Find what: [([^]]*)]
    Replace With: [\U$1\E]

    Finds everything between [ and ], inclusive, saving the stuff between the brackets as $1
    The \U and \E say to make everything between those two escapes uppercase. Thus \U$1\E uppercases 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$0

    Note, Kurt, that the two search regexes, from Peter and me, would match a “multi-lines” square-bracket block, too, as, for instance :


    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)[.*?]



    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 :-((

Log in to reply