Search and Replace for CNC Help Needed
-
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. toF[#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 needF[#23*300.toF[#23*1.15for 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 CHECKEDI 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 CHECKEDUnfortunatley 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 -
Your second was on the right track:
FIND =
F(\d+[.]\d*)
REPLACE =F[#23*$1]
SEARCH MODE = Regular Expression
DOT MATCHES = not checkedThe parentheses in the FIND put the number into capture group #1
The$1in 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) -
That worked great!
Seems there is a whole level I was not aware of.
Still much to learn.Thanks for your help!
-
Still much to learn.
Useful References:
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