我正在做一些 Gcode 机器指令,我需要在行首添加一条指令,其中每个第一个实例F 180.0
都会跳过第二个
例如
G00 X 0.0000 Y 0.0000 Z 10.0000
G00 X 24.5230 Y 44.6619 Z 5.0000
G01 X 24.5230 Y 44.6619 Z 0.0000 F 180.0
G01 X 24.5585 Y 45.2432 Z 0.0000 F 180.0
G01 X 24.6723 Y 45.8451 Z 0.0000
会成为
G00 X 0.0000 Y 0.0000 Z 10.0000
G00 X 24.5230 Y 44.6619 Z 5.0000
M03 G01 X 24.5230 Y 44.6619 Z 0.0000 F 180.0
G01 X 24.5585 Y 45.2432 Z 0.0000 F 180.0
G01 X 24.6723 Y 45.8451 Z 0.0000
我猜想可能会使用相同的原理,但是我需要在每一行中添加Z5.0000
G00 X 0.0000 Y 0.0000 Z 10.0000
M05 G00 X 24.5230 Y 44.6619 Z 5.0000
M03 G01 X 24.5230 Y 44.6619 Z 0.0000 F 180.0
G01 X 24.5585 Y 45.2432 Z 0.0000 F 180.0
G01 X 24.6723 Y 45.8451 Z 0.0000
答案1
- Ctrl+H
- 找什么:
\A(?:(?:(?!\bF 180\.0\b).)+\R)+\K^(?=.+?\bF 180\.0\b)
- 用。。。来代替:
M03
<-- M03 后面有一个空格 - 查看 相符
- 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
* - Replace all
解释:
\A # beginning of file
(?: # non capture group ()
(?: # non capture group (1 line that doesn't contain F 180.0)
(?! # negative lookahead, make sure we haven't after:
\b # word boundary
F 180\.0 # literally
\b # word boundary
) # end lookahead
. # any character but newline
)+ # end group, may appear 1 or more times
\R # any kind of line break
)+ # end group, may appear 1 or more times
\K # forget all we have seen until this position(i.e. skip all lines before the first occurrence of F 180.0)
^ # beginning of line
(?= # positive lookahead, make sure we have after:
.+? # 1 or more any character but newline, not greedy
\b # word boundary
F 180\.0 # literally
\b # word boundary
) # end lookahead
屏幕截图(之前):
屏幕截图(之后):
第二次替换类似,但更简单:
- 找什么:
^(?=.+?\bZ 5.0000\b)
- 用。。。来代替:
M03
屏幕截图(之后):