Help locating a letter and number string
-
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 restrictionsI 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
-
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+
- if it’s really G0 - G9, not just G0, then it can be changed to to
- 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]
- match must start with G0 followed by one space , but don’t include that prefix in the highlighted match
-
@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. -
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.
-
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 fileSEARCH
(?-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