Replace lowercase with uppercase between brackets



  • Need to change varying text between square brackets to UPPERCASE.

    Change [help wanted] to [HELP WANTED]

    Found an Tried the following regex:

    [([^]\r\n]*)] … Invalid regular expression!
    Invalid regular expresion.jpg (see pic attached)

    (?-s)[.*?] … All this does is finds . and/or ? in the file

    [([^]]*)] … Invalid regular expression



  • @Hank-K said in Replace lowercase with uppercase between brackets:

    Need to change varying text between square brackets to UPPERCASE.

    Your regex was close and it gave me a starting point for one that does work.

    Find What:(?<=[)([^]\r\n]+)
    Replace With:\U\1

    See if that helps you. Now currently it will not edit a string if that string goes over 2 (or more) lines. If you need to allow for multiple lines you could change the find what code to (?<=[)([^]]+).

    Give it a go and please do tell us how you got on, even if not working and let us know what strings it missed. We could alter to suit.

    Terry

    PS forgot to say I also changed the * to a +. In order to change any characters to upper case there must be at least 1 otherwise no sense in selecting it.



  • Tried both same, Invalid regular expression!
    Invalid regular expresion R1.jpg

    Does it work for you ? Here’s the exact portion of the text:

    1
    00:00:01,042 --> 00:00:02,919
    [door squeaks open]

    2
    00:00:02,961 --> 00:00:04,337
    [clears throat]

    3
    00:00:04,379 --> 00:00:06,172
    [keys jangle]

    Thanks for the assist Terry … what am I doing wrong ?



  • So, Terry probably meant the regex to be (?<=\[… but this site has some weirdness with posting the backslash-then-left-bracket syntax.

    The fact that the first [ is not escaped is probably the problem here.



  • @Hank-K said in Replace lowercase with uppercase between brackets:

    Invalid regular expression!

    The forum mangles backslash followed by [ , even in `backticks`, which make just about everything appear literal

    The first should be bd9b459f-1abe-4727-a1e9-edef1d7f4719-image.png

    The second should be 26aef4d2-31ea-4489-b374-b4cba11cc3ce-image.png

    (edit: i unnecessarily escaped the ] in the first one but not the second. talk about consistency; it’ll still find the same things)



  • @Alan-Kilborn said in Replace lowercase with uppercase between brackets:

    The fact that the first [ is not escaped is probably the problem here.

    Yep, right first time. I forgot that bloody interpreter has a way with certain characters, thanks @Alan-Kilborn for providing that fix.

    Terry

    PS apologies @Hank-K , good to see that the seasoned forum members are there to help out. We’ll get you there eventually.

    PPS, so the alternate regex also needs the \ added in the same location.



  • The accomplishment of an aim or purpose.
    SUCCESS

    Thanks so MUCH for the quick replies GUYS … 2 thumbs ~~



  • This post is deleted!


  • If I wanted to ignore existing UPPERCASE between the brackets ? ? ?
    Using it in “Find in Files” mode … have a lot existing cases.

    Trying to MATCH existing files is what started this epic journey … lol



  • @Hank-K said in Replace lowercase with uppercase between brackets:

    If I wanted to ignore existing UPPERCASE between the brackets ? ? ?

    That would complicate matters and is probably unnecessary as you want to make all (alpha) characters inside the [] uppercase, who cares if the regex picks one set which is already so, it doesn’t change the outcome, still upper case characters are produced.

    At the moment the regex picks ALL the characters together, so if some were already upper case do you wish to exclude those and only convert the remainder to upper case. That could be done with a regex, but honestly I think it serves no useful purpose. The conversion to uppercase is what matters, unless we are missing something you wish to convey but haven’t been able to so far?

    Terry



  • NP …Thanks again Terry … Cheers


Log in to reply