Regex replace escape $

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Adam Weigert Adam Weigert 1 year, 10 months ago.

  • Author
    Posts
  • #25842
    Profile photo of Adam Weigert
    Adam Weigert
    Participant

    Trying to get -replace to escape the first $ in this statement: 'TRUE' -replace '(TRUE|FALSE)','$$1'

    Have tried \, and ` with no luck. It just outputs $1 each time.

    Thoughts?

  • #25843
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Are you trying to replace 'TRUE' with '$TRUE'? If so, you need one more $ in your string. (The first two $$ are a literal $ in the output, and then $1 is the replacement token).

    As a bonus, here's how you'd update your pattern to only inject the dollar sign if it wasn't already there:

    Edit: Moved code over to a gist, the forum was converting some of my single-quotes to double for some weird reason.

  • #25844
    Profile photo of Adam Weigert
    Adam Weigert
    Participant

    Thanks just tried that lol.

You must be logged in to reply to this topic.