Skip to main content
RigidCollision
Participant
March 10, 2022
Question

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

  • March 10, 2022
  • 3 replies
  • 1095 views

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 has been closed for replies.

    3 replies

    Community Expert
    March 11, 2022
    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.

    Community Expert
    March 11, 2022

    *DW doesn't act as expected

    Community Expert
    March 11, 2022

    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

    Nancy OShea
    Community Expert
    Community Expert
    March 10, 2022

    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.

     

     

    Nancy O'Shea— Product User & Community Expert