• Login
Community
  • Login

Help locating a letter and number string

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
line replacegcoderegexsort
5 Posts 3 Posters 1.3k 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.
  • A
    Angela Davis
    last edited by Jul 5, 2018, 2:54 PM

    Hello Everybody. I am looking to sort some G code and am having a bit of trouble figuring out how to find certain lines

    One line might read:

    N106 G0 X-.3352 Y.103

    I need to be able to find the section above where the digit after “X” can be positive or negative and may or may not include a decimal place and can vary in length
    The “Y” number has the same restrictions

    I want to locate: GO X(whatever is here) Y(whatever is here)

    The “N” number before is irrelevant to me and i DONT want it included in the selection

    Any help would be greatly appreciated!

    Thanks,

    Jeff

    1 Reply Last reply Reply Quote 0
    • P
      PeterJones
      last edited by PeterJones Jul 5, 2018, 4:21 PM Jul 5, 2018, 4:18 PM

      So, this selects the X through the end of the Y’s number: G0 X[-+]*\d*\.*\d+ Y[-+]*\d*\.*\d+:

      • match must start with G0 followed by one space , but don’t include that prefix in the highlighted match
        • if it’s really G0 - G9, not just G0, then it can be changed to to G\d
        • if it’s actually G followed by one or more digits, use to G\d+
      • literal X
      • followed by zero or more literal pluses and minuses (so X-.3352 or X+.3352 or X.3352)
      • followed by zero or more digits (this allows X+.3352 or X+52.33)
      • followed by optional literal period (being optional means it will also match X-3352)
      • followed by one or more digits
      • followed by a literal space
      • then followed by a literal Y, with the same sign, digits, points, digits requirements as the X had

      For more information, study the docs listed in the regex faq .

      If this doesn’t solve your problem, please provide more info . You’ll notice in my description, there was some mention of places where your specification had ambiguity, and I was making a best guess. Additional examples of lines that should match and providing lines that shouldn’t match will help make the .

      [edit/PS: regular expressions must be enabled; sorry I forgot to mention]

      1 Reply Last reply Reply Quote 2
      • A
        Angela Davis
        last edited by Jul 5, 2018, 4:44 PM

        @PeterJones said:

        G0 X[-+]\d.\d+ Y[-+]\d*.*\d+

        WOW!, Spot on.
        Well done. Thank you very much for taking the time to help me and also write a description. The description is very helpful.

        1 Reply Last reply Reply Quote 1
        • A
          Angela Davis
          last edited by Jul 5, 2018, 5:04 PM

          Also, is there a way to switch lines in regex? For example CtrlT in the shortcut commands will swap a line with its above line; but i cant figure out how to do this thru search and replace.

          1 Reply Last reply Reply Quote 0
          • G
            guy038
            last edited by Jul 5, 2018, 7:26 PM

            Hello, @angela-davis

            Assuming there is NO condition on the choice of lines, this following regex S/R swaps, for instance, the next 2 lines till the final block of two lines of the current file

            SEARCH (?-s)^(.*\R)(.+\R)

            REPLACE \2\1

            So, given the sample text, below, with the cursor located before the string 1A :

            1A This is a
            1B simple text
            2A in order to
            2B understand
            3A how the
            3B text changes
            

            You should get :

            1B simple text
            1A This is a
            2B understand
            2A in order to
            3B text changes
            3A how the
            

            Best regards,

            guy038

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