Community
    • Login

    only replace exact numbers

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    14 Posts 4 Posters 1.2k 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.
    • CynicC
      Cynic @Terry R
      last edited by

      @Terry-R the XXX is just for any numbers really. The numbers I want to change would be followed by a space yes

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R
        last edited by

        One possible Replace function is
        Find What:0\.5([^\d])
        Replace With:0.3\1
        As it’s a regular expression search mode must be set to regular expression and have wrap around ticked.

        So it looks for your 0.5 and as long as the next character is NOT a digit it will be replaced. Since we actually selected the next character we write it back behind the replacement number (0.3).

        See if that helps. Otherwise come back if it needs refinement. There are quite a few ways this can be solved. This is a just a quick one I typed up.

        Terry

        CynicC 1 Reply Last reply Reply Quote 4
        • CynicC
          Cynic @Terry R
          last edited by

          @Terry-R It works perfectly :) Thanks a lot!

          1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @Cynic
            last edited by

            @Cynic said in only replace exact numbers:

            the XXX is just for any numbers really

            With the addition of this info it doesn’t seem like the regex works.

            1 Reply Last reply Reply Quote 0
            • Terry RT
              Terry R
              last edited by

              @Alan-Kilborn said in only replace exact numbers:

              With the addition of this info it doesn’t seem like the regex works.

              Well I used the following for the test:

              0.5 something
              0.5 nothing here
              0.5434
              0.4 doesn't really matter to me
              0.5 help I'm last in line!
              

              and then after my regex was run I have:

              0.3 something
              0.3 nothing here
              0.5434
              0.4 doesn't really matter to me
              0.3 help I'm last in line!
              

              Looks like it worked. Am I missing something?

              Terry

              Alan KilbornA 1 Reply Last reply Reply Quote 1
              • Alan KilbornA
                Alan Kilborn @Terry R
                last edited by

                @Terry-R

                Nope, sorry,
                I read what the OP wanted wrongly.

                I’m (generally) not one to “shorten” regexes that work, but what about this pair as illustrating a different technique for this situation:

                find: 0\.5(?=\D)
                repl: 0.3

                1 Reply Last reply Reply Quote 3
                • Olivier ThomasO
                  Olivier Thomas
                  last edited by Olivier Thomas

                  It can be like that?
                  Find What:0\.5\s
                  Replace With:0.3\s

                  Even easier instead of \s you can insert a space

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @Olivier Thomas
                    last edited by

                    @Olivier-Thomas said in only replace exact numbers:

                    Even easier instead of \s you can insert a space

                    Not necessarily.
                    OP did not include info about whitespace.
                    That was inferred in the example data @Terry-R provided, which may or may not be indicative of the situation the OP has.
                    Unless I’m reading it wrongly yet again (very possible!).

                    It really wouldn’t be up for debate if the OP had just provided the same thing we ask for here again and again and again, and most of the time we don’t get: Sample BEFORE and sample AFTER data!

                    1 Reply Last reply Reply Quote 0
                    • Olivier ThomasO
                      Olivier Thomas
                      last edited by

                      Unfortunately, I can only answer after 20 minutes.

                      I am for shortening.
                      instead of this
                      ([2-3]|0[2-3]|00[2-3]|[2-9][2-3]|0[2-9][2-3]|\d[02-9][2-3])
                      it’s better to write like this:
                      ((\d[02-9]|[2-9])*)[2-3]

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @Olivier Thomas
                        last edited by

                        @Olivier-Thomas said in only replace exact numbers:

                        Unfortunately, I can only answer after 20 minutes.

                        That is because you previously ruined your reputation here.

                        I am for shortening.

                        IMO shortening something that works has little value…if we’re talking about a one-off replacement op in a text file in Notepad++.

                        Now, shortening something that is used in a production program, well, that could be a different story.

                        Sure, shortening a regex can make it more efficient.
                        But sometimes shortening a regex actually has to make the regex engine work harder (i.e., take more processing time, possibly overflow, etc) or invites more “risk”. Do we want this in a production environment? I’d say no.

                        So, the true answer, again IMO, cannot be the simple one of “I am for shortening”. But…you go ahead believing what you want to. :-)

                        Note to future readers: The regex that @Olivier-Thomas put forth in the previous posting has nothing to do with the original-poster’s problem.

                        1 Reply Last reply Reply Quote 0
                        • Olivier ThomasO
                          Olivier Thomas
                          last edited by

                          In the IVONA voice-over for film subtitles
                          I have over 6000 abbreviated commands.

                          I did not notice that the IVONA lector did not keep up with reading the text.

                          Alan KilbornA 1 Reply Last reply Reply Quote 0
                          • Alan KilbornA
                            Alan Kilborn @Olivier Thomas
                            last edited by

                            @Olivier-Thomas said in only replace exact numbers:

                            In the IVONA voice-over for film subtitles
                            I have over 6000 abbreviated commands.
                            I did not notice that the IVONA lector did not keep up with reading the text.

                            I’m not sure what this means.
                            Do you care to explain a bit, if it is relevant?
                            After 20 minutes, of course… :-)

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