Community
    • Login

    Very new to notepad++

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    37 Posts 3 Posters 4.9k 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.
    • John RussellJ
      John Russell @Alan Kilborn
      last edited by

      @alan-kilborn said in Very new to notepad++:

      @john-russell said in Very new to notepad++:

      No I had that changed just in my example I hadn’t

      Well, we aren’t mind readers here. To get good help, you have to accurately convey what you’ve tried and what you still need assistance with.

      Yeah even when its changed to editor.rereplace(r'EngineResponsiveness="(\d*\.?\d+.\d+)"', multiply_by_2) it isn’t working (Just thought Id try just encase I made the same mistake :P)

      1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @John Russell
        last edited by PeterJones

        @john-russell ,

        I just randomly added .\d+ so the code looked like this howManyblueitems=\d+.\d+ and it worked and replaced the ones with decimals as well.

        Your random experiments deceived you. . in a regular expression matches any character, so your howManyblueitems match would have matched the 5.14 that is reasonable, but it would also have matched 5x14 which would have then not worked for the muliply-by-2; you were just lucky you didn’t have any accidental matches.

        editor.rereplace(r'Torque="(\d*\.?\d+.\d+)"', multiply_by_2)

        Why would you do such a thing?! I already told you that the expression I gave you, \d*\.?\d+ matches a number with a decimal point in it. Specifically, it matches 0 or more digits, 0 or one decimal points, and 1 or more digits. That matches 5 or .5555 or 5.5555555555555 all equally well.

        If you think r'EngineResponsiveness="(\d*\.?\d+)"' doesn’t match EngineResponsiveness="0.35", then you will need to show us data that proves this.

        But now I read and I see that your most recent example has Torque Value=70000 (which has an extra word and no quotes) and EngineResponsiveness=0.35 (which has no quotes), so then my question would be “why do you think that a regex which requires quotes around a value would match a value that is missing the quotes?”. A regex that is looking for EngineResponsiveness="0.35" can never match text that is EngineResponsiveness=0.35, no matter how much you might wish it so.

        Also, there is 0 chance that the Torque script you showed would have matched your Torque Value=70000. Be explicit and accurate about your data and what you have tried, or we are unable to help you.

        ----

        Useful References

        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find regular expressions (regex) documentation
        John RussellJ 1 Reply Last reply Reply Quote 0
        • John RussellJ
          John Russell @PeterJones
          last edited by

          @peterjones said in Very new to notepad++:

          If you think r’EngineResponsiveness=“(\d*.?\d+)”’ doesn’t match EngineResponsiveness=“0.35”, then you will need to show us data that proves this.

          If you think r'EngineResponsiveness="(\d*\.?\d+)"' doesn’t match EngineResponsiveness="0.35", then you will need to show us data that proves this.
          Unless I’m missing what you mean?? It doesn’t work for anything with a decimal! Unless decimals in Notepad++ mean something else?

          Here’s a link (Hopeful Vimeo don’t compress to much so its not watchable) to what I’m doing and you can see it doesn’t work. I’m probably doing something wrong but I don’t what that is.
          link text

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

            @alan-kilborn said in Very new to notepad++:

            there’s a good starting point for putting together a bit more of a demo – I’ll try to do this, and perhaps it will give you a better start.

            I’m going to back down on this offer.
            There is too much uncertainty and it seems lack of understanding on the part of the OP.
            Sorry…

            John RussellJ 1 Reply Last reply Reply Quote 1
            • John RussellJ
              John Russell @Alan Kilborn
              last edited by

              @alan-kilborn said in Very new to notepad++:

              @alan-kilborn said in Very new to notepad++:

              there’s a good starting point for putting together a bit more of a demo – I’ll try to do this, and perhaps it will give you a better start.

              I’m going to back down on this offer.
              There is too much uncertainty and it seems lack of understanding on the part of the OP.
              Sorry…

              Come on? I’m simply saying it didn’t work as intended and have shown you proof like you asked. I don’t like how you expect me to know this so quickly its whole new language its would take years in programming or something like that to know so quickly.

              def calculate(match):
                  return '%s' % (str(int(match.group(1)) * 10))
              
              editor.rereplace('(\d+)', calculate)```
              
              This works for all values including ones with decimals but then it doesn't have the feature of limiting it to a predefined term like```EngineResponsiveness="0.35"```
              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @John Russell
                last edited by PeterJones

                @john-russell ,

                I found the problem.

                The reason it was not changing was because int("0.35") was giving an error message in the PythonScript console that we were not seeing:

                Traceback (most recent call last):
                  File "C:\usr\local\apps\npp\npp.8.4.2.portable.x64\plugins\Config\PythonScript\scripts\Multiply.py", line 7, in <module>
                    editor.rereplace(r'EngineResponsiveness="(.*?)"', multiply_by_2)
                  File "C:\usr\local\apps\npp\npp.8.4.2.portable.x64\plugins\Config\PythonScript\scripts\Multiply.py", line 5, in multiply_by_2
                    return 'EngineResponsiveness="' + str(int(m.group(1)) * 2) + '"'
                ValueError: invalid literal for int() with base 10: '0.35'
                

                You did not read or understand in the example where it said,

                To convert the text of a group to a number in python, use int(m.group(1)) to make it an integer, or float(m.group(1)) to make it a floating point number.

                You were supposed to then understand that if you want Python to treat the string as a floating point number, you needed to use float(m.group(1)), not int(m.group(1)).

                I should have remembered, as soon as you said “nothing happened”, to have you turn on Plugins > Python Script > Show Console to look for errors.

                This works (proven):

                # encoding=utf-8
                from Npp import editor
                
                def multiply_by_2(m):
                    return 'EngineResponsiveness="' + str(float(m.group(1))*2) + '"'
                
                editor.rereplace(r'EngineResponsiveness="(\d*\.?\d*.\d+)"', multiply_by_2)
                

                I don’t like how you expect me to know this so quickly its whole new language its would take years in programming or something like that to know so quickly.

                We don’t expect you to know all this immediately. What we expect is that you understand that this is a complicated task – not the simple search and replace you assumed – and that it’s really not a problem that should be solved in Notepad++ or any other text editor, but rather in a programming language, and that you should understand we’ve already explained that this forum is not a general “write code for me” forum, or even “help me write my code”. This is about Notepad++, but your discussion has been about a very specific set of data manipulation requirements which we’ve explained multiple times cannot be handled by search-and-replace alone. But you keep on posting as if you expect us to do all this for you. So we keep trying to help you, despite the fact that it’s moved way off topic from a text editor question.

                But if we are going to continue to help you – volunteering our time to help you do something that’s only microscopically related to the topic of this forum – then you are going to have to put in the effort. Things like saying Torque Value=70000 when you mean Torque="70000" or saying EngineResponsiveness=0.35 when you mean EngineResponsiveness="0.35" are not helping your cause, and are not putting in the effort. Saying “it didn’t work” or “nothing happened” are not putting in the effort.

                If you are going to try random things – which is allowed – you are going to have to show us exactly what you tried when it didn’t work, not some approximation that doesn’t actually match reality.

                If you had said

                I have the following exact text:

                <EngineVariants>
                    <Engine
                
                        DamageCapacity="120"
                
                        EngineResponsiveness="0.35"
                    >
                        ...
                    </Engine>
                </EngineVariants>
                

                and I ran the exact script

                # encoding=utf-8
                from Npp import editor
                
                def multiply_by_2(m):
                    return 'EngineResponsiveness="' + str(int(m.group(1))*2) + '"'
                
                editor.rereplace(r'EngineResponsiveness="(\d*\.?\d*.\d+)"', multiply_by_2)
                

                but it did nothing. I think it is not matching the decimal point correctly, so I tried
                editor.rereplace(r'EngineResponsiveness="(\d*\.?\d+.\d+)"', multiply_by_2) instead, but that still didn’t work

                If you had said that, we would have had the exact representation of what you had tried, and we could have copy/pasted it into our own Notepad++, and we could have seen that nothing happened for us either.

                Instead, you gave text that didn’t match your actual data, and then after much prompting showed a video which we had to click somewhere else to see, that showed you using a regex that we hadn’t suggested (so it was proving your regex bad, if anything, not that the one I supplied was bad). It took me 15 minutes just to watch the video enough and type up some example text and try to recreate the exact circumstances enough to replicate your problem. And then that long again to type things up in a way that I hope you will understand and take to heart.

                John RussellJ 2 Replies Last reply Reply Quote 1
                • John RussellJ
                  John Russell @PeterJones
                  last edited by

                  @peterjones said in Very new to notepad++:

                  @john-russell ,

                  I found the problem.

                  The reason it was not changing was because int("0.35") was giving an error message in the PythonScript console that we were not seeing:

                  Traceback (most recent call last):
                    File "C:\usr\local\apps\npp\npp.8.4.2.portable.x64\plugins\Config\PythonScript\scripts\Multiply.py", line 7, in <module>
                      editor.rereplace(r'EngineResponsiveness="(.*?)"', multiply_by_2)
                    File "C:\usr\local\apps\npp\npp.8.4.2.portable.x64\plugins\Config\PythonScript\scripts\Multiply.py", line 5, in multiply_by_2
                      return 'EngineResponsiveness="' + str(int(m.group(1)) * 2) + '"'
                  ValueError: invalid literal for int() with base 10: '0.35'
                  

                  You did not read or understand in the example where it said,

                  To convert the text of a group to a number in python, use int(m.group(1)) to make it an integer, or float(m.group(1)) to make it a floating point number.

                  You were supposed to then understand that if you want Python to treat the string as a floating point number, you needed to use float(m.group(1)), not int(m.group(1)).

                  I should have remembered, as soon as you said “nothing happened”, to have you turn on Plugins > Python Script > Show Console to look for errors.

                  This works (proven):

                  # encoding=utf-8
                  from Npp import editor
                  
                  def multiply_by_2(m):
                      return 'EngineResponsiveness="' + str(float(m.group(1))*2) + '"'
                  
                  editor.rereplace(r'EngineResponsiveness="(\d*\.?\d*.\d+)"', multiply_by_2)
                  

                  I don’t like how you expect me to know this so quickly its whole new language its would take years in programming or something like that to know so quickly.

                  We don’t expect you to know all this immediately. What we expect is that you understand that this is a complicated task – not the simple search and replace you assumed – and that it’s really not a problem that should be solved in Notepad++ or any other text editor, but rather in a programming language, and that you should understand we’ve already explained that this forum is not a general “write code for me” forum, or even “help me write my code”. This is about Notepad++, but your discussion has been about a very specific set of data manipulation requirements which we’ve explained multiple times cannot be handled by search-and-replace alone. But you keep on posting as if you expect us to do all this for you. So we keep trying to help you, despite the fact that it’s moved way off topic from a text editor question.

                  But if we are going to continue to help you – volunteering our time to help you do something that’s only microscopically related to the topic of this forum – then you are going to have to put in the effort. Things like saying Torque Value=70000 when you mean Torque="70000" or saying EngineResponsiveness=0.35 when you mean EngineResponsiveness="0.35" are not helping your cause, and are not putting in the effort. Saying “it didn’t work” or “nothing happened” are not putting in the effort.

                  If you are going to try random things – which is allowed – you are going to have to show us exactly what you tried when it didn’t work, not some approximation that doesn’t actually match reality.

                  If you had said

                  I have the following exact text:

                  <EngineVariants>
                      <Engine
                  
                          DamageCapacity="120"
                  
                          EngineResponsiveness="0.35"
                      >
                          ...
                      </Engine>
                  </EngineVariants>
                  

                  and I ran the exact script

                  # encoding=utf-8
                  from Npp import editor
                  
                  def multiply_by_2(m):
                      return 'EngineResponsiveness="' + str(int(m.group(1))*2) + '"'
                  
                  editor.rereplace(r'EngineResponsiveness="(\d*\.?\d*.\d+)"', multiply_by_2)
                  

                  but it did nothing. I think it is not matching the decimal point correctly, so I tried
                  editor.rereplace(r'EngineResponsiveness="(\d*\.?\d+.\d+)"', multiply_by_2) instead, but that still didn’t work

                  If you had said that, we would have had the exact representation of what you had tried, and we could have copy/pasted it into our own Notepad++, and we could have seen that nothing happened for us either.

                  Instead, you gave text that didn’t match your actual data, and then after much prompting showed a video which we had to click somewhere else to see, that showed you using a regex that we hadn’t suggested (so it was proving your regex bad, if anything, not that the one I supplied was bad). It took me 15 minutes just to watch the video enough and type up some example text and try to recreate the exact circumstances enough to replicate your problem. And then that long again to type things up in a way that I hope you will understand and take to heart.

                  that this forum is not a general "write code for me" Sadly some people learn this way and I’m one of those people. I don’t do well with text books I’m more hands on kind of guy (Practical Learning).

                  Just some of the language you were typing was coming off a little aggressive which I’m sure you didn’t mean to be. Heres an example
                  Are you seriously expecting a search term containing Torque= to match something containing EngineResponsiveness= ?

                  I just took slight offense to it. I’m human we make mistakes but I understand that you wouldn’t of know that it was a mistake

                  It would of just come off a bit more friendly if you had said Your mistake is "Your search term need to match 'EngineResponsiveness=' and not read 'Torque+'.

                  Then I could of just replied oh yeah silly me I typed it wrong in the example shown but I wrote it correctly in the script and is still not working

                  Anyway thanks for handling this maturely unlike most people on the internet. Good Job and I will take a look at the code you have sent in a little bit :)

                  1 Reply Last reply Reply Quote 0
                  • John RussellJ
                    John Russell @PeterJones
                    last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • John RussellJ
                      John Russell
                      last edited by PeterJones

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • John RussellJ
                        John Russell
                        last edited by

                        Above code works perfectly 😁 Thank You 👍

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