Community
    • Login

    Find & Replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 5 Posters 495 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.
    • Blair RollinsonB
      Blair Rollinson
      last edited by PeterJones

      Hello, I am a very basic user of Notepad++

      I have a file that I would like to make a number of changes to a particular text within the file without affecting other variables in the text string

      An example is
      I have approximately 660 entries of the following text

       <p n='OSS_HeatingSetPoint' h='123eb7' t='c:NumericPoint'>
      

      However, the ‘123eb7’ will change line to line

      I need to be able to find ‘OSS_HeatingSetPoint’
      And change ‘c:NumericPoint’
      To ‘c:NumericWritable’

      Without affecting the ‘123eb7’ number (this number will change line to line so need to ignore this)

      If someone could offer any assistance, would be greatly appreciated.

      Regards

      Blair

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Blair Rollinson
        last edited by

        @Blair-Rollinson ,

        Using regex (SEARCH MODE = Regular Expression), there are multiple ways of doing it. One such solution, assuming that the <p ....> tags always have the n/h/t attributes are always in that order, always with single quotes, always with a single space in between:

        • FIND = (<p n='OSS_HeatingSetPoint' h='.*?' t=)'c:NumericPoint'>
          REPLACE = $1'c:NumericWriteable'>
          SEARCH MODE = Regular Expression
          do not checkmark ☐ . matches newline

        The (…) section of the regex puts all of that text into group#1, and the $1 in the replacement says “use the value of group1 here”. The '.*?' in the h-attribute’s value means “match 0 or more of any character (except a newline) between the single quotes”.

        If your HTML isn’t perfectly regular like that (if attributes are in different orders, or sometimes the attributes use double quotes instead of single quotes, or if the paragraph tag internals are split across multiple lines instead of in one line like you showed), then my simple regex won’t work, and you will need to read and understand our FAQ as to why regex should not be used to edit JSON/HTML/XML. But if your HTML is perfectly regular, my regex might just work for you.

        ----

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • Formatting Forum Posts
        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        1 Reply Last reply Reply Quote 4
        • Blair RollinsonB
          Blair Rollinson
          last edited by PeterJones

          Hello Peter

          Thanks for the help
          That work great
          I have tweaked the search to find various search strings

          However, I have a couple of more searches which I think the $ sign in the search is screwing up the search as it fails to find any results
          I assume the $ means something in the search function

            <p n="DamperPos$40SetPoint" h="7d" t="c:NumericPoint">
             <p n="$30$25_Select" h="81" t="c:BooleanPoint">
            <p n="$324_7_Required" h="a2" t="c:BooleanPoint">
          

          Can you advise how to include the $ in the search string

          Regards

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • Blair RollinsonB
            Blair Rollinson
            last edited by

            Hello Peter

            I found out how to do it
            I think I am all good now

            Thanks for your help

            1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @Blair Rollinson
              last edited by

              @Blair-Rollinson said in Find & Replace:

              I assume the $ means something in the search function
              Can you advise how to include the $ in the search string

              …

              I found out how to do it

              For anyone who is reading this, and wonders what the mysterious fix was: $ in a regular expression search means “end of line”; to match the literal $ character in a Search Mode = Regular Expression search, it needs to be “escaped” as \$

              1 Reply Last reply Reply Quote 2
              • guy038G
                guy038
                last edited by guy038

                Hello, @blair-rollinson, @peterjones and All,

                To complete the @peterjones’s reply, here are all the ways to search for a literal $ sign, within N++ :

                • When the Normal search mode is set :

                  • $ ( the character itself )

                • When the Extended search mode is set :

                  • \d036 ( decimal value )

                  • \x24 ( Hexadecimal value )

                  • \o044 ( Octal value )

                  • \b00100100 ( Binary value )

                • When the Regular expression search mode is set, running the Boost regex engine :

                  • First, you can use the escaped value of this character : \$

                  • Secondly, you can place this character within a character class : [$]

                  • Thirdly, you may use its hexadecimal Unicode value, so one of the three syntaxes : \x24 or \x{24} or \x{0024}

                  • Fourthly, you may use its octal Unicode value, so one of the txo syntaxes : \044 or \0044

                  • Fifthly, you may use its symbolic value , so one of the two syntaxes : \N{dollar-sign} or, inside a class character [[.dollar-sign.]]


                Of course, you certainly guess that I personally use the Regular expression search mode and, like everybody, the most simple syntax, i.e. \$

                Best Regards,

                guy038

                Alan KilbornA Terry RT 2 Replies Last reply Reply Quote 1
                • Alan KilbornA
                  Alan Kilborn @guy038
                  last edited by

                  @guy038 said in Find & Replace:

                  For this:

                  When the Extended search mode is set :

                  You forgot one:

                  $ ( the character itself )

                  1 Reply Last reply Reply Quote 2
                  • Terry RT
                    Terry R @guy038
                    last edited by Terry R

                    @guy038 said in Find & Replace:

                    When the Regular expression search mode is set, running the Boost regex engine :

                    And
                    Sixthly, you may use \Q$\E which allows any characters within the \Q and \E to be accepted as literals within a regular expression. In this example the $ is the literal character.

                    1 Reply Last reply Reply Quote 3
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors