正则表达式在Notepad ++中的括号中查找/替换值

时间:2015-06-24 05:07:41

标签: regex replace find notepad++

我是Regex的新手,我想我的问题不会太难回答。 我正在尝试使用Notepad ++编辑G代码,并且我需要更改一些括号组合以使机器工作。 我想将任何嵌套的括号(在G代码中的注释)替换为_content_

例如,我想替换

N33(8141(31) -- Roughing 2)

有关

N33(8141_31_ -- Roughing 2)

嵌套括号中的内容是1到50之间的数字,所以我想解决方案会包含一系列值,例如[1-50]。

这是G代码的修剪样本。兴趣点是N33,N160和N299:

%
<7641-MF1>
N1(PROGRAM NAME      : )
N2(PART NAME         :)
N3(PROGRAM DATE      :)
N4(PROGRAMMED BY     :Alejo)
N5(POWERMILL PROJECT :7641-MF1
N6(MACHINE TOOL :CMS & MODEL :)
N7(CONTROLLER :)
N8(OPTION FILE :)
N9(POWERMILL CB      :)
N10(OUTPUT WORKPLANE  :G55)
N11(TOOL LIST :  3 TOOLS )
N12(---------------------------------------------------------------------------)
N13(Tool Number|            Tool Name|Tool Diameter|Tool Tip Radius|Tool Length)
N14(---------------------------------------------------------------------------)
N15(         15|             Tool15|           80|             .0|        296)
N16(          9|              Tool9|          127|             .0|       2418)
N17(          5|              Tool5|        19125|             .0|       2275)
N18(---------------------------------------------------------------------------)
N19(ESTIMATED CUTTING TIME :  383 TOOLPATHS =1 hours 20 min 5 sec)
N20G21
N21G92.1X0Y0Z0B0C0
N22G55
N23G5.1Q0
N24G52X0Y0Z0
N25G53G90G00G49Z-200H0
N26(TOOL NUMBER : T15)
N27(TOOL NAME : Tool15)
N28(TOOL TYPE : ENDMILL)
N29(TOOL DIAMETER : 80 & LENGTH : H296)
N30T15M6
N31H15
N32G359
N33(8141(31) -- Roughing 2)
N34M3S17000F30000.
N35G43.4H15
N36G1G90X24.855Y140.392B40.0C66.176F30000.
N37G5.1Q1R1
N38Z50.0
N153X187.216Y187.99Z19.445B40.0C142.536
N154X187.162Y188.367Z19.775B40.0C142.536
N155X187.162Y188.367Z19.775B40.0C142.536F30000.
N156X187.162Y188.367Z50.0B40.0C142.536
N157G5.1Q1R1
N158Z50.0
N159X226.555Y251.806Z50.0B-45.559C98.447
N160(8141(30) -- Roughing 1)
N161X226.555Y251.806Z50.0B-45.559C98.447F5000.
N162X226.555Y251.806Z25.058B-45.559C98.447
N292X40.523Y188.223Z18.547B-33.984C134.954
N293X40.502Y187.868Z18.904B-33.984C134.954
N294X40.502Y187.868Z18.904B-33.984C134.954F30000.
N295X40.502Y187.868Z50.0B-33.984C134.954
N296G5.1Q1R1
N297Z50.0
N298X24.855Y285.258Z50.0B40.0C66.176
N299(8141(30) -- Roughing 2)
N300X24.855Y285.258Z50.0B40.0C66.176F5000.
N301X24.855Y285.258Z26.13B40.0C66.176
N302X25.523Y283.851Z24.902B40.0C66.176
N417X187.162Y333.234Z19.775B40.0C142.536F30000.
N418X187.162Y333.234Z50.0B40.0C142.536

2 个答案:

答案 0 :(得分:1)

试试这个正则表达式:\(.*(?=\()(.)[0-9][0-9](\))

使用括号捕获嵌套的(),将\ 1和\ 2替换为_

Demo

答案 1 :(得分:0)

输入:

(\(.*)(?=\().([0-9]{2})\)

查找内容:\1_\2_
替换为:N160(8141_30_ -- Roughing 1) N33(8141_31_ -- Roughing 2)

输出:

routes.php

Explanation