Skip to main content
RigidCollision
Participant
Mar 10, 2022 9:30 PM UTC
Question

Find and Replace using Regex - change $1 Result to uppercase?

Hi,

I am doing a regex search:

//\s+([a-zA-Z])

To find all lines that  match this:

 

// test

// another test

...

I would like to change the first char to uppercase. I thought I could  use the following in the replace:

// \U$1

to instruct the $1 result to be upper case but this doesn't work in dreamweaver.

Is there a way of instructing the search and replace dialogue to alter the $ output?

    This topic is closed to new replies. Start a new post to keep the conversation going.

    4 replies

    Community Expert
    Mar 11, 2022 7:37 AM UTC
    quote

    // test

    // another test

    ...

    By @RigidCollision

    Youps, sorry, when I saw my answer displayed, I understood that, in your question,  the lines starting with / corresponded to your search fields, so, your initial query and your replacement expression are quite correct.

    They should work, if not, DW acts as expected, switch to Notepad++.
    Sorry again for the noise.

    Translate
    Community Expert
    Mar 11, 2022 7:38 AM UTC

    *DW doesn't act as expected

    Translate
    Community Expert
    Mar 11, 2022 7:24 AM UTC

    Indeed, the 

    \U$1

    instruction does not work in DW but as expected in Notepad++.

     

    However (unless you want it to), the initial request you make includes the invisible characters before any first letter, which results in the removal of that character when replacing.

    In addition, this query also includes characters that are already capitalized, which is not necessary in itself.

     

    So, I would suggest replacing your query with

    (\b[a-z](?!\s))

    And

    \U$1

     If I find an alternative in DW, I will come back to this post, but often, I make the REGEX in Notepad++, even in Vim

    Translate
    Nancy OShea
    Community Expert
    Community Expert
    Mar 10, 2022 11:26 PM UTC

    I don't follow.  Can you be more specific?  Give us some examples of the target string you're searching for and what should replace it.

     

     

    Translate
    Nancy O'Shea— Product User & Community Expert