Community
    • Login

    Search and Replace for CNC Help Needed

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 75 Views 2 Watching
    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.
    • P Offline
      Paul Adamczyk
      last edited by

      Fellow Notepad++ Users,

      Could you please help me the the following search-and-replace problem I am having?

      I am writing CNC programs. I modify the output from my CAM system to use a variable feedrate. The characters can be different depending on which system I’m writing for. Typically there are only a few lines that I change manually, but for certain cycles there are thousands of lines.

      Basically, I need to change F300. to F[#23*300.], but the F word can have 1-3 digits to the left of the decimal, and 0-2 digits to the right.
      With simple Find/Replace I can get everything I need F[#23*300. to F[#23*1.15 for example, but I can’t get the closing bracket.

      Note, I only need to modify the F word, it only occurs at the end of a line.

      Before data:

      G1 Z-.51 Q66.
      X1.4004Y.8297Z-.5129F300.
      G3X1.4193Y.7497Z-.52I.052J-.03F150.
      X1.6025Y.6946I.1832J.277F85.58
      X1.6582Y.6993J.3321
      X1.7857Y.7497I-.0557J.3274F171.16
      X1.8046Y.8295Z-.513I-.0331J.05F300.
      G1X1.7857Y.8625Z-.51
      X1.3014Q500.
      

      After Data:

      G1 Z-.51 Q66.
      X1.4004Y.8297Z-.5129F[#23*300.]
      G3X1.4193Y.7497Z-.52I.052J-.03F[#23*150.]
      X1.6025Y.6946I.1832J.277F[#23*85.58]
      X1.6582Y.6993J.3321
      X1.7857Y.7497I-.0557J.3274F[#23*171.16]
      X1.8046Y.8295Z-.513I-.0331J.05F[#23*300.]
      G1X1.7857Y.8625Z-.51
      X1.3014Q500.
      

      I did this with the simple Find/Replace and then adding the closing bracket manually.
      *Find = F
      *Replace With = F[#23*
      *Search Mode = NORMAL
      *Dot Matches Newline = NOT CHECKED

      I did uses Regex with the following search term to Find all of the words I need to modify.

      *Find = F\d+[.]\d*
      *Replace With =
      *Search Mode = REGULAR EXPRESSION
      *Dot Matches Newline = NOT CHECKED

      Unfortunatley I have exhausted my mental ablities with that and cannot figure out how to do the Replacement

      Thanks in advance for your help.

      –
      moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” and ` around inline text like regex, so that characters don’t get changed by the forum

      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP Online
        PeterJones @Paul Adamczyk
        last edited by PeterJones

        @Paul-Adamczyk said:

        Your second was on the right track:

        FIND = F(\d+[.]\d*)
        REPLACE = F[#23*$1]
        SEARCH MODE = Regular Expression
        DOT MATCHES = not checked

        The parentheses in the FIND put the number into capture group #1
        The $1 in the replacement says “use the contents of capture group #1”

        (Personally, I would use \. instead of [.] to match a literal dot character, but your notation works, so I left it the way you understand it)

        P 1 Reply Last reply Reply Quote 1
        • P Offline
          Paul Adamczyk @PeterJones
          last edited by

          @PeterJones

          That worked great!
          Seems there is a whole level I was not aware of.
          Still much to learn.

          Thanks for your help!

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP Online
            PeterJones @Paul Adamczyk
            last edited by

            @Paul-Adamczyk said:

            Still much to learn.

            Useful References:

            • Notepad++ Online User Manual: Searching/Regex
            • FAQ: Where to find other regular expressions (regex) documentation
            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors