Community
    • Login

    I need to replace some numbers....

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    10 Posts 4 Posters 777 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 McDoeJ
      John McDoe
      last edited by

      Hi guys, I need to replace some numbers: specifically I need to replace the 6 digit bold numbers with 6 ZEROES only at the SPECIFIC lines: (lines that begin with “Vertex”)
      The random 6 digit bold numbers appear randomly ONLY after the “.”
      They are always 6 digit and always random.
      Put in other words: I need to make sure that on every line that begins with “Vertex” after the DOT I have 6 ZEROES. Always.
      Thanx in advance!

      Begin PolyList
      Begin Polygon
      Origin -00128.000000,-00128.000000,-00128.000000
      Normal -00001.000000,+00000.000000,+00000.000000
      TextureU +00000.000000,+00001.000000,+00000.000000
      TextureV +00000.000000,+00000.000000,-00001.000000
      Vertex -00128.768546,-00128.000000,-00128.766453
      Vertex -00128.000000,-00128.000000,+00128.000000
      Vertex -00128.000000,+00131.756453,+00128.000000
      Vertex -00128.000000,+00131.000000,-00128.000000
      End Polygon

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @John McDoe
        last edited by

        @John-McDoe

        find what:^Vertex.*\.\K(?!0{6})(\d{6})
        replace with:000000

        Note, because of the \K usage you need to press replace all, replace doesn’T work in this case and you need to keep press replace all unless you receive that
        nothing was replaced anymore.

        If you want to learn more about the regex checkout the NEW NPP MANUAL SITE.

        1 Reply Last reply Reply Quote 1
        • John McDoeJ
          John McDoe
          last edited by

          Hi, thank you but its not working because I made a mistake and skipped some spaces:

          This is how the line (a single line for example only) looks:

          Vertex +02096.560547,+00774.871582,+00078.723633

          There are 3 spaces after the word “Vertex” that somehow disappeared.

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

            @John-McDoe

            They disappeared because this forum uses Markdown syntax in posts. If you want to show data without markdown messing with it, do a line like this before and after your data: ~~~

            Thus:

            ~~~
            hello there
            ~~~

            will look like this when posting:

            hello  there
            
            1 Reply Last reply Reply Quote 1
            • John McDoeJ
              John McDoe
              last edited by

              Can someone give me a working solution? The one posted by @Ekopalypse does not work.

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones
                last edited by PeterJones

                @John-McDoe said:

                The one posted by @Ekopalypse does not work.

                Maybe not. But it’s an excellent starting point. You could choose to study the docs (see below, and the link Eko posted), and then try to modify @Ekopalypse’s regex to fit your needs. If you cannot get it to work, you can show us what you tried (and why you think that should have worked), what you got, and what you expect.

                Show some effort, and you’ll get lots of help. Don’t show any effort, and you’ll probably eventually get the answer anyway, but will have to wait longer, and will probably use up any free goodwill you may have started with.

                -----

                Please Read And Understand The Following

                FYI:

                This forum is formatted using Markdown, with a help link buried on the little grey ? in the COMPOSE window/pane when writing your post. For more about how to use Markdown in this forum, please see @Scott-Sumner’s post in the “how to markdown code on this forum” topic, and my updates near the end. It is very important that you use these formatting tips – using single backtick marks around small snippets, and using code-quoting for pasting multiple lines from your example data files – because otherwise, the forum will change normal quotes ("") to curly “smart” quotes (“”), will change hyphens to dashes, will sometimes hide asterisks (or if your text is c:\folder\*.txt, it will show up as c:\folder*.txt, missing the backslash). If you want to clearly communicate your text data to us, you need to properly format it. That topic also explains how to embed images by uploading them to a public server like imgur.com, and embedding them using the syntax ![](http://i.imgur.com/QTHZysa.png)

                If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study this FAQ and the documentation it points to, especially this. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting, see the paragraph above.

                Please note that for all regex and related queries, it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.

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

                  @John-McDoe said:

                  Can someone give me a working solution?

                  Can you post some data that you are sure is correct? People tend to lose interest after a few posts where people can’t do this…

                  1 Reply Last reply Reply Quote 0
                  • John McDoeJ
                    John McDoe
                    last edited by

                    HI again. I did everything that @Ekopalypse said correct. I tripple checked everything.

                    In the end, I did a macro, that does the job for me, it worked, but I’d like to be able to do it using the way he described too.

                    I have given all the information that is required in my previous post, just note that after “Vertex” there are always 3 spaces, not 1.

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

                      @John-McDoe said:

                      I have given all the information that is required in my previous post

                      Where “all the information” doesn’t including showing exactly what you tried (you make us do the work of “three spaces” because you have shown yourself unwilling to follow simple instructions for quoting exact text), doesn’t include showing us what you got when you tried it, doesn’t include showing why you think the result was wrong. That seems like “I have given you the bare minimum of information, which isn’t actually enough to solve my problem, and then blame you when the free help doesn’t work exactly the way I want it to”.

                      If that’s how you want to come across, leave things as they are. If you want to come across as someone who is willing to learn, and who is willing to make an effort, and who wants help rather than just demanding a solution, I would suggest adding information and rephrasing things.

                      1 Reply Last reply Reply Quote 1
                      • PeterJonesP
                        PeterJones
                        last edited by PeterJones

                        But at this point, I’m not sure I want to run the risk of you blaming us anymore for your problem. Hopefully this post will show you what happened.

                        When I started with

                        Begin PolyList
                        Begin Polygon
                        Origin -00128.000000,-00128.000000,-00128.000000
                        Normal -00001.000000,+00000.000000,+00000.000000
                        TextureU +00000.000000,+00001.000000,+00000.000000
                        TextureV +00000.000000,+00000.000000,-00001.000000
                        Vertex   -00128.768546,-00128.000000,-00128.766453
                        Vertex   -00128.000000,-00128.000000,+00128.000000
                        Vertex   -00128.000000,+00131.756453,+00128.000000
                        Vertex   -00128.000000,+00131.000000,-00128.000000
                        End Polygon
                        

                        with your three pesky spaces (or without, because it doesn’t affect the regex at all), and run @ekopalypse’s regex once with REPLACE ALL, it fixes two of the three instances:

                        Begin PolyList
                        Begin Polygon
                        Origin -00128.000000,-00128.000000,-00128.000000
                        Normal -00001.000000,+00000.000000,+00000.000000
                        TextureU +00000.000000,+00001.000000,+00000.000000
                        TextureV +00000.000000,+00000.000000,-00001.000000
                        Vertex   -00128.768546,-00128.000000,-00128.000000
                        Vertex   -00128.000000,-00128.000000,+00128.000000
                        Vertex   -00128.000000,+00131.000000,+00128.000000
                        Vertex   -00128.000000,+00131.000000,-00128.000000
                        End Polygon
                        

                        Then I run it a second time, and it fixes the third instance.

                        Begin PolyList
                        Begin Polygon
                        Origin -00128.000000,-00128.000000,-00128.000000
                        Normal -00001.000000,+00000.000000,+00000.000000
                        TextureU +00000.000000,+00001.000000,+00000.000000
                        TextureV +00000.000000,+00000.000000,-00001.000000
                        Vertex   -00128.000000,-00128.000000,-00128.000000
                        Vertex   -00128.000000,-00128.000000,+00128.000000
                        Vertex   -00128.000000,+00131.000000,+00128.000000
                        Vertex   -00128.000000,+00131.000000,-00128.000000
                        End Polygon
                        

                        The reasons this happens is because of the way the regex engine works inside of Notepad++: The first match found the start of the line, followed by Vertex, followed by as many characters as it could, until it hit the literal period that wasn’t before 6 zeroes. That means in -00128.768546,-00128.000000,-00128.766453 that it gobbled up all the characters until it found 766453 (the second set of non-zero decimal-fraction digits)… that’s then the fraction that it replaced with 000000 on that row. But at that point, the search cursor had moved beyond that line, so it didn’t see that the line still matches the regex. Hence it left that line as

                        Vertex   -00128.768546,-00128.000000,-00128.000000
                        

                        When you run the regex a second time, it gets rid of the second match earlier in the line.

                        If @Ekopalypse had used a non-greedy regex ^Vertex.*?\.\K(?!0{6})(\d{6}) (the extra ? makes it non-greedy), then it would have fixed the 768546 on the first run of the regex, and 766453 on the second.

                        Either way, just run the regex more than once, and it will work for you. If there are three numbers possible on each line (and given “polygon” and “vertex”, I am assuming that those are 3d coordinates, so three seems a reasonable max-per-line), then you should only have to run the regex a maximum of 3 times to get all the replacements done.

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