<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[reGex Find copy and replace to a new line.]]></title><description><![CDATA[<p dir="auto">Hello.<br />
I need help in a regex syntax to be able to transform the gcode for my CNC machine</p>
<hr />
<p dir="auto">The following is a sample of  gcode, my machine cannot read or execute.</p>
<p dir="auto">Numbers at the beginning of each line, are not really exist in code.<br />
I added them just for this post.<br />
<strong>AND</strong><br />
Line1 means Program Start and line40 program end.<br />
Lines 2 to 16 are usefull for the machine.<br />
Lines 17 to 29 are notes for the user.<br />
<em>All these LINES (1-29) have to stay as they are</em>.</p>
<p dir="auto"><strong>The real code machine executes is in lines</strong><br />
30 and 31<br />
32 and 33<br />
34 and 35<br />
36 and 37<br />
38 and 39</p>
<p dir="auto"><strong>Here is the sample code</strong></p>
<ol>
<li>%</li>
<li>|1 P3002</li>
<li>|2 0</li>
<li>|3 13</li>
<li>|4 180.00</li>
<li>|5 44.30</li>
<li>|6 180.00</li>
<li>|7 0 0 0 0</li>
<li>|8 0</li>
<li>|9</li>
<li>|10</li>
<li>|11</li>
<li>|12</li>
<li>|13</li>
<li>|14</li>
<li>:3002</li>
<li>(-----------------------------</li>
<li>( |&gt;DATE:Monday July 04 2022</li>
<li>( |&gt;TIME:05:26 PM</li>
<li>( TOOLS USED ,T1 = Drill - 5mm Dia</li>
<li>( TOOLS USED ,T7 = Drill - 5.7mm Dia</li>
<li>( TOOLS USED ,T3 = Drill - 8mm Dia</li>
<li>( TOOLS USED ,T6 = Drill - 7.8mm Dia</li>
<li>( TOOLS USED ,T2 = Drill - 4mm Dia</li>
<li>( TOOLS USED ,T5 = Drill - 10mm Dia</li>
<li>(</li>
<li>(</li>
<li>(</li>
<li>(-----------------------------</li>
<li>G172 X-74.305 Y-67.956 Z0.000 S17 E2 T1</li>
<li>G100 X-74.305 Y-67.956 Z15.220 F2</li>
<li>G172 X-74.305 Y-52.511 Z0.000 S17 E2 T7</li>
<li>G100 X-74.305 Y-52.511 Z10.03 F1</li>
<li>G172 X-74.305 Y-37.496 Z0.000 S17 E2 T3</li>
<li>G100 X-74.305 Y-37.496 Z11.000 F3</li>
<li>G172 X-74.305 Y-23.338 Z0.000 S17 E2 T3</li>
<li>G100 X-74.305 Y-23.338 Z12.000 F1</li>
<li>G172 X-74.734 Y-11.326 Z0.000 S17 E2 T9</li>
<li>G100 X-74.734 Y-11.326 Z12.000 F4</li>
<li>%</li>
</ol>
<p dir="auto"><strong>Lines 30,32,34,36,38</strong> (starting with G172)  are useless.   I have this regex  <strong>^G172.*\R</strong>   to delete them and move the following line (starting with G100) one up.</p>
<p dir="auto">But in these lines (starting with G172) there is one information i must keep before deleting.</p>
<p dir="auto">In line30, i need the last digit wich is number 1<br />
or the last 2 digits T1<br />
In line32, i need the last digit wich is number 7<br />
or …T7<br />
In line34, last digit is number 3<br />
or…T3<br />
In line36, number 3…or T3<br />
In line38, number 9…or T9<br />
<em>This number is always a digit between 1-9.</em></p>
<p dir="auto">I can mark them with several ways but i prefer this<br />
<strong>(?&lt;=T)\d$</strong> cause it has no effect on other lines.</p>
<p dir="auto"><strong>What i need is</strong> to copy digit 1 from line30, paste it to the end of the next line (line31) including a space and letter T in front of this number and then delete line30 and move 31 one line up.<br />
<strong>or</strong><br />
to copy last two digits from line30, T1 and then paste them at the end of line32, including one space before them, delete line30, move line31 one up.<br />
<strong>It is also necessary</strong> to replace same way to the next lines of code.<br />
T1 form line30 to the end of line31<br />
T7 from line32 to the end of line33<br />
.<br />
.<br />
.</p>
<p dir="auto">So<br />
<strong>Old format  was</strong><br />
.<br />
.<br />
30. G172 X-74.305 Y-67.956 Z0.000 S17 E2 T1<br />
31. G100 X-74.305 Y-67.956 Z15.220 F2<br />
32. G172 X-74.305 Y-52.511 Z0.000 S17 E2 T7<br />
33. G100 X-74.305 Y-52.511 Z10.03 F1<br />
34. G172 X-74.305 Y-37.496 Z0.000 S17 E2 T3<br />
35. G100 X-74.305 Y-37.496 Z11.000 F3<br />
36. G172 X-74.305 Y-23.338 Z0.000 S17 E2 T3<br />
37. G100 X-74.305 Y-23.338 Z12.000 F1<br />
38. G172 X-74.734 Y-11.326 Z0.000 S17 E2 T9<br />
39. G100 X-74.734 Y-11.326 Z12.000 F4<br />
40. %</p>
<p dir="auto">And the <strong>New format must be</strong> like this<br />
.<br />
.<br />
30. G100 X-74.305 Y-67.956 Z15.220 F2 T1<br />
31. G100 X-74.305 Y-52.511 Z10.03 F1 T7<br />
32. G100 X-74.305 Y-37.496 Z11.000 F3 T3<br />
33. G100 X-74.305 Y-23.338 Z12.000 F1 T3<br />
34. G100 X-74.734 Y-11.326 Z12.000 F4 T9<br />
35. %</p>
<p dir="auto">Thanks in front<br />
Evangelos</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/23198/regex-find-copy-and-replace-to-a-new-line</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 17:27:27 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/23198.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Jul 2022 22:44:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to reGex Find copy and replace to a new line. on Tue, 05 Jul 2022 11:42:48 GMT]]></title><description><![CDATA[<p dir="auto">Thank you for your direct responce.<br />
It works great.</p>
<p dir="auto">Its perfect</p>
<p dir="auto">Thank you again<br />
Evangelos</p>
]]></description><link>https://community.notepad-plus-plus.org/post/78142</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/78142</guid><dc:creator><![CDATA[Evangelos Kosmas]]></dc:creator><pubDate>Tue, 05 Jul 2022 11:42:48 GMT</pubDate></item><item><title><![CDATA[Reply to reGex Find copy and replace to a new line. on Mon, 04 Jul 2022 22:57:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/evangelos-kosmas" aria-label="Profile: Evangelos-Kosmas">@<bdi>Evangelos-Kosmas</bdi></a> said in <a href="/post/78122">reGex Find copy and replace to a new line.</a>:</p>
<blockquote>
<p dir="auto">I need help in a regex syntax to be able to transform the gcode for my CNC machine</p>
</blockquote>
<p dir="auto">As your example has been altered (by you adding line numbers) and possibly by the posting engine as you did not put the example inside of a black box (see <a href="https://community.notepad-plus-plus.org/topic/22022/faq-desk-template-for-search-replace-questions">this FAQ post</a>) my solution may or may not work. I’m hoping it will as the regex you provided for deleting the G172 line does help.</p>
<p dir="auto">So using the Replace function we have:<br />
Find What:<code>(?-s)^G172.*(T\d)\R(.+)</code><br />
Replace With:<code>\2 \1</code>   note there is a space between <code>\2</code> and <code>\1</code>.<br />
So I just extended what you already had, including the T digit portion on the first line, also selecting the entire second line and then writing back the portions you wanted to keep.</p>
<p dir="auto">See if it works and please do come back to us either way. if you need to post further examples please read that FAQ post I linked to above.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/78123</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/78123</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Mon, 04 Jul 2022 22:57:15 GMT</pubDate></item></channel></rss>