regex question

Welcome Forums General PowerShell Q&A regex question

Viewing 3 reply threads
  • Author
    Posts
    • #236032
      Participant
      Topics: 21
      Replies: 32
      Points: 309
      Rank: Contributor

      hi all,

      Been trying for 2 hours to find the regex to replace a portion of a string. In my string, I have # Start and # End. I need a regex that would capture # Start including what precedes it, another capture for # End and all that follows it, and insert a new string inside of that.

      Example:

      line of text

      line of text

      # Start

      # End

      line of text

       

      would become

      line of text

      line of text

      # Start

      Inserted text

      could be multi-line

      # End

      line of text

       

      Thank you very much!

    • #236041
      Participant
      Topics: 5
      Replies: 2372
      Points: 6,005
      Helping Hand
      Rank: Community MVP

      Daniel
      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

      What have you tried so far? We expect you to make an own attempt to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

      Have you tried to search for a solution first? Questions like this have been asked and answered already even here in this forum.

    • #236125
      Participant
      Topics: 21
      Replies: 32
      Points: 309
      Rank: Contributor

      got it for the code format.

      i tried many variations of a regex but haven’t been able to make it work yet.

      but i managed to read the content and parse each line to a foreach loop taht did what i’m looking for.

      thanks!

    • #236203
      Participant
      Topics: 5
      Replies: 2372
      Points: 6,005
      Helping Hand
      Rank: Community MVP

      got it for the code format.

      Sorry but No, you did not!

      i tried many variations of a regex but haven’t been able to make it work yet.

      Please show your code!

Viewing 3 reply threads
  • You must be logged in to reply to this topic.