Reputation: 13
I am completely new to Regex and I guess my question wouldn't be too hard to answer.
I am trying to edit G-code with Notepad++ and there are some combination of parenthesis that I need to change in order to make the machine work.
I want to replace any nested parenthesis (which are comments in G-code) into _content_
For example, I want to replace
N33(8141(31) -- Roughing 2)
For
N33(8141_31_ -- Roughing 2)
The content in the nested parenthesis are numbers from 1 to 50, so I guess the solution would include a range of values, such as [1-50].
This is a trimmed sample of the G-code. The lines of interests are N33, N160 and 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
Upvotes: 1
Views: 950
Reputation: 23737
Input:
N160(8141(30) -- Roughing 1)
N33(8141(31) -- Roughing 2)
Find What: (\(.*)(?=\().([0-9]{2})\)
Replace with: \1_\2_
output:
N160(8141_30_ -- Roughing 1)
N33(8141_31_ -- Roughing 2)
Upvotes: 0
Reputation: 782
Try this regex: \(.*(?=\()(.)[0-9][0-9](\))
Use parentheses to capture nested (
and )
, replace \1 and \2 with _
.
Upvotes: 1