• Login
Community
  • Login

Search and Replace

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 3 Posters 582 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C
    Claude Martin
    last edited by Nov 24, 2022, 4:47 PM

    Fellow Notepad++ Users,

    Could you please help me with the following search-and-replace problem I am having?

    I need to search and replace in different documents with a line like
    <property name=“CarryWeight” value=“1”/>

    The value changes and can be any number and I want to rplace the value with a number of my choosing.

    Here is the data I currently have (“before” data):

    <property name="CarryWeight" value="1"/>
    <property name="CarryWeight" value="20"/>
    
    Here is how I would like that data to look (“after” data):
    
    <property name="CarryWeight" value="0"/>
    <property name="CarryWeight" value="0"/>
    
    I feel this is something thats doable but my last computer class was in 1972 and I don'
    remember Fortran covering this. :)
    Thanks
    A 1 Reply Last reply Nov 24, 2022, 5:10 PM Reply Quote 0
    • A
      Alan Kilborn @Claude Martin
      last edited by Nov 24, 2022, 5:10 PM

      @Claude-Martin

      Are you saying your doc has other “property name” sections, but you only want to change your value in those that have the name CarryWeight?

      C 1 Reply Last reply Nov 24, 2022, 5:24 PM Reply Quote 0
      • C
        Claude Martin @Alan Kilborn
        last edited by Claude Martin Nov 24, 2022, 5:25 PM Nov 24, 2022, 5:24 PM

        @Alan-Kilborn Yes. I could search and replace manually but three of the files have over 7000 lines of code.

        A 1 Reply Last reply Nov 24, 2022, 7:02 PM Reply Quote 0
        • A
          Alan Kilborn @Claude Martin
          last edited by Nov 24, 2022, 7:02 PM

          @Claude-Martin

          What you want is to search and replace only between other text. We have a prior solution for that. See if you can follow the RECIPE for that, but for your specific data.

          C N 2 Replies Last reply Nov 24, 2022, 7:43 PM Reply Quote 0
          • C
            Claude Martin @Alan Kilborn
            last edited by Nov 24, 2022, 7:43 PM

            @Alan-Kilborn Thank you I’ll give a go.

            1 Reply Last reply Reply Quote 0
            • N
              Neil Schipper @Alan Kilborn
              last edited by Nov 24, 2022, 8:15 PM

              @Alan-Kilborn said in Search and Replace:

              What you want is to search and replace only between other text.

              You may be right, but nothing in what @Claude-Martin originally showed, nor in the subsequent exchange between you, supports the need for selectively acting on property name="CarryWeight" lines bound by specified higher level tags.

              My reading of the need leads me to think simple regex solutions should be satisfactory:

              
              1) replace a specific group of nums with a specific num
              
              Fi: <property name="CarryWeight" value="(?:1|3|15|20)"/>
              Re: <property name="CarryWeight" value="PLACE_NEW_NUM_HERE"/>
              
              or
              
              2) replace all nums with a specific num
              
              Fi: <property name="CarryWeight" value="\d+"/>
              Re: <property name="CarryWeight" value="PLACE_NEW_NUM_HERE"/>
              
              
              A 1 Reply Last reply Nov 24, 2022, 8:18 PM Reply Quote 2
              • A
                Alan Kilborn @Neil Schipper
                last edited by Nov 24, 2022, 8:18 PM

                @Neil-Schipper

                Yes, indeed, it may very well be the simpler case. I was fooled because so often these go the other way. :-)

                1 Reply Last reply Reply Quote 2
                4 out of 7
                • First post
                  4/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors