• Login
Community
  • Login

Replace sets of numbers in a given position with 0

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 323 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.
  • F
    Fernando Bernabeu
    last edited by May 30, 2022, 1:36 PM

    Hello!
    I’ve been trying to look for a solution to this problem I have by using Regular Expressions, but I’ve come up empty.
    I have a pose file for a 3D model and the line I want to modify looks like this:

    Hips: 5.5 5.5 2.8 -0.0248 -0.0071 -0.0215 1 1 1

    The first three sets of numbers between spaces are rotation, the next three are position and the last three are size. The position sets of numbers can have up to 4 decimal numbers.
    What I want to do is replace the position sets of numbers with 0, so I could end up with a line like this:

    Hips: 5.5 5.5 2.8 0 0 0 1 1 1

    Would there be a way to specifically replace the 4th, 5th and 6th set of numbers between spaces with 0?
    Big TIA

    N 1 Reply Last reply May 30, 2022, 2:21 PM Reply Quote 0
    • N
      Neil Schipper @Fernando Bernabeu
      last edited by May 30, 2022, 2:21 PM

      @fernando-bernabeu

      Here’s a solution with a very loose spec. It doesn’t care what the contents of the first 4+3=7 fields are, only that they are chunks of text separated by a single space.

      Ctl-h
      Fi: ^(?:(?:.*? ){4})\K((?:.*? ){3})
      Re: 0 0 0 <=== trailing space needed!
      Mode=regex; option box unchecked

      Then: Replace All

      What I want to do is replace the position sets of numbers with 0

      You don’t actually state that you want to do this for every occurrence in a file but that’s what I’ve assumed.

      N 1 Reply Last reply May 30, 2022, 2:32 PM Reply Quote 1
      • N
        Neil Schipper @Neil Schipper
        last edited by May 30, 2022, 2:32 PM

        Here’s an expression with a somewhat tighter spec, in case file contains lines with different starting text you wish to ignore: ^Hips: (?:(?:.*? ){3})\K((?:.*? ){3})

        We can make it even tighter, such as validating that the other pieces consist of digits, maybe with decimal points, etc.

        F 1 Reply Last reply May 31, 2022, 6:38 AM Reply Quote 1
        • F
          Fernando Bernabeu @Neil Schipper
          last edited by May 31, 2022, 6:38 AM

          @neil-schipper
          Thank you very much! That worked wonderfully!

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