我正在執行一些 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
螢幕截圖(之後):