I am trying to create a Pythonscript program to convert old CNC programs to a newer format. I am using the editor.rereplace() format to do this and have most of my functions working this way. I am having trouble with one specific format. In Notepad++ I would use Find/Replace with the following conditions to achieve what I want, line by line.
This removes any spaces in the program that are NOT inside of parenthesis and that would otherwise make every other function more difficult. I cannot seem to get that Find function working in Pythonscript. I have tried adding enumerable escapes ( \ ) and nothing seems to be working for me. Can anyone help me with the proper formatting to make this work? Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you post a few lines of "before" and "after"? I tried your Find regex in N++, and it just did "odd things" to some text I created, so I think I must have a misunderstanding somewhere about what you are trying to achieve.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
o1234
(EXAMPLE PROGRAM)
(THIS IS A CNC COMMENT)
(I WANT THESE LINES TO RETAIN SPACES)
()
G28G91Z0
T1M6(EXAMPLE TOOL)
M3S10000
G90G0G95G54X1.0Y2.0
G43Z0.25H1D1M8
G1Z-1.0F0.006
X-1.0Y-2.0
Y2.0
X1.0
G0Z1.0M5
G28G91Z0M9
M01(CHECK PART)
So the goal is to remove every space in the program that is not within parenthesis. This "normalizes" the program so that all of my other regex's work without needing special clauses for spaces. This doesn't affect the way the program is read by the CNC machine and isn't really even a nuisance for the people working with the file as we're used to seeing programs both ways (with and without spaces). Hopefully that makes sense?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
that's pretty easy if you know the right Built-In-String Operation. The <string>.replace(<old>, <new>) operation helps you most.
importredefmatch_found(m):myString=m.group()returnmyString.replace(' ','£')# Send terms in parentheses to function for protecting spaces inside with £-sign.editor.rereplace('\([^\(]+\)',match_found)# Delete all spaces. \h is the regex expression for all horizontal spaces, tabs and so on.editor.rereplace('\h','')# Substitute £-sign with spaceseditor.rereplace('£',' ')
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried posting some code here but it won't let me. This forum is kinda dead anyway. Why don't you repost your question here?: https://notepad-plus-plus.org/community
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to create a Pythonscript program to convert old CNC programs to a newer format. I am using the editor.rereplace() format to do this and have most of my functions working this way. I am having trouble with one specific format. In Notepad++ I would use Find/Replace with the following conditions to achieve what I want, line by line.
Find: ((.?))|(a-z([-#]?\d(.\d)?))\s
Replace: $1$2
This removes any spaces in the program that are NOT inside of parenthesis and that would otherwise make every other function more difficult. I cannot seem to get that Find function working in Pythonscript. I have tried adding enumerable escapes ( \ ) and nothing seems to be working for me. Can anyone help me with the proper formatting to make this work? Thanks!
Can you post a few lines of "before" and "after"? I tried your Find regex in N++, and it just did "odd things" to some text I created, so I think I must have a misunderstanding somewhere about what you are trying to achieve.
Here is a quick and dirty example.
Before:
After:
So the goal is to remove every space in the program that is not within parenthesis. This "normalizes" the program so that all of my other regex's work without needing special clauses for spaces. This doesn't affect the way the program is read by the CNC machine and isn't really even a nuisance for the people working with the file as we're used to seeing programs both ways (with and without spaces). Hopefully that makes sense?
Hi Andrew,
that's pretty easy if you know the right Built-In-String Operation. The <string>.replace(<old>, <new>) operation helps you most.
Maybe not so easy huh?
I tried posting some code here but it won't let me. This forum is kinda dead anyway. Why don't you repost your question here?: https://notepad-plus-plus.org/community