<?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[Find and Replace]]></title><description><![CDATA[<p dir="auto">Hello.  I was hoping someone may be able to help me with an issue I am having.  I have a large text document of code for a CNC machine I am running.  I need to make a replacement to some code within the document.  I think I can do it with notepad++, but I am not sure how.  I will give an example of a few lines, and also what I would like them to look like after…</p>
<p dir="auto">++BEFORE++<br />
G1 X1.2 Z.300 F0.001<br />
G2 X0.2063 Z.350 R0.45<br />
Y0.34 X.5 R.1</p>
<p dir="auto">++AFTER++<br />
G1 X[#501* 1.2] Z.300 F0.001<br />
G2 X[#501* 0.2063] Z.350 R0.45<br />
Y0.34 X[#501* .5] R.1</p>
<p dir="auto">As you can see, I need to multiply every X value by the “#501” variable and add brackets to the whole equation.  Thanks for any suggestions!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/16245/find-and-replace</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 03:17:00 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/16245.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Aug 2018 04:38:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 20:39:31 GMT]]></title><description><![CDATA[<p dir="auto">Ok, good to know!  Thanks again guys for all the help!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34500</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34500</guid><dc:creator><![CDATA[Jeremy H]]></dc:creator><pubDate>Thu, 30 Aug 2018 20:39:31 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 20:22:15 GMT]]></title><description><![CDATA[<p dir="auto">Doing math goes beyond the realm of pure regular expressions inside notepad++.</p>
<p dir="auto">At this point, you’ve reached the stage of needing a full programming language, preferably one with easy access to regular expressions, like Perl or Python.  You could then leverage the regexes we’ve already written to parse the data, and grab out the value into a variable; you could then double it, and put that doubled value back into the data stream.  It could be a command-line utility, or if you use PythonScript, you could actually do it live inside Notepad++.</p>
<p dir="auto">I know there have been some of these G# X# Y# Z# regex questions in the forums before, and doing math on them sounds vaguely familiar to me.   Someone may have written a PythonScript that might help with that.  There is a rudimentary search of the forums through the magnifying glass at the top of the page, or use a google advanced search with <code>site:notepad-plus-plus.org/community</code>.  Good luck</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34499</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34499</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 30 Aug 2018 20:22:15 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 20:22:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeremy-h" aria-label="Profile: Jeremy-H">@<bdi>Jeremy-H</bdi></a></p>
<blockquote>
<p dir="auto">…replacing them with a doubled value…</p>
</blockquote>
<p dir="auto">No can do…at least not with the methods thus far discussed.  One would have to resort to scripting for that kind of replacement.</p>
<p dir="auto">A very similar thing is discussed in the Pythonscript documentation for the <code>editor.rereplace()</code> function, as an example, in this case adding one to each integer match found (very coincidentally also following an <code>X</code>!!):</p>
<pre><code class="language-z">def add_1(m):
    return 'Y' + str(number(m.group(1)) + 1)

# replace X followed by numbers by an incremented number
# e.g.   X56 X39 X999
#          becomes
#        Y57 Y40 Y1000

editor.rereplace('X([0-9]+)', add_1);
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/34498</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34498</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Thu, 30 Aug 2018 20:22:32 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 20:20:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeremy-h" aria-label="Profile: Jeremy-H">@<bdi>Jeremy-H</bdi></a><br />
Regex does NOT do equations, that is other than replacing 1 string with another string it does not “on the fly” calculate a mathematical result and insert that into the replacement field.<br />
You’d need to go to either a programming language to achieve this, or firstly look for all the unique instances within the file, then work out a replacement string for each one. A regex could then do the replacement.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34497</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34497</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Thu, 30 Aug 2018 20:20:53 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 20:06:13 GMT]]></title><description><![CDATA[<p dir="auto">Thanks, that seems to work just like I need it to.  One more request of it is not too much trouble.  I would also like to try to change these x values by replacing them with a doubled value.  I am not sure how the replace feature handles actual equations though.  It seems like it should be pretty simple, I wouldn’t need brackets or anything it would simply be…</p>
<p dir="auto">X.7 or X0.7 or X0.7000<br />
to<br />
X1.4</p>
<p dir="auto">Negative values would need to be doubled as well.  Thanks!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34496</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34496</guid><dc:creator><![CDATA[Jeremy H]]></dc:creator><pubDate>Thu, 30 Aug 2018 20:06:13 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 16:36:07 GMT]]></title><description><![CDATA[<p dir="auto">As long as you aren’t worried about <code>X.</code>,  then a simplified version of mine will work: <code>X(-?[0-9]*\.[0-9]*)</code></p>
<ul>
<li>0 or 1 negative sign</li>
<li>possible digits</li>
<li>required decimal point</li>
<li>possible digits</li>
</ul>
<p dir="auto">For more regex details, see the <a href="https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation" rel="nofollow ugc">FAQ</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/34493</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34493</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 30 Aug 2018 16:36:07 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 16:28:38 GMT]]></title><description><![CDATA[<p dir="auto">So after testing, it looks like Scott solution worked very well for me. Except for one unforeseen issue. Our control also uses X as an argument. I do not want to change he argument value.  I tried to find a common pattern between all arguments vs x values and it looks like every value contains a decimal point and all arguments do not.  So I am wondering if we can exclude any match that does not include a decimal?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34492</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34492</guid><dc:creator><![CDATA[Jeremy H]]></dc:creator><pubDate>Thu, 30 Aug 2018 16:28:38 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 16:17:52 GMT]]></title><description><![CDATA[<p dir="auto">I know.  I just couldn’t help myself dig into it more on this one.</p>
<p dir="auto">Oh, re-reading the original post, I see that <code>X.5</code> is valid, so need to convert my <code>+</code> to a <code>*</code>.  Of course, that opens up the bug that it could conceivably match <code>X </code> with nothing after it, because all the optional items optioned out. :-)  I won’t fix it, since the OP seems happy with the simpler ones you both provided.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34491</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34491</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 30 Aug 2018 16:17:52 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 15:22:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a></p>
<blockquote>
<p dir="auto">…nitpicking…</p>
</blockquote>
<p dir="auto">I view it as we’re just here to kickstart an OP into a solution, not deliver a fully QA’d exact solution…so if an OP doesn’t specifically ask for something, what they get back can and probably should be minimal.  :-D</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34490</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34490</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Thu, 30 Aug 2018 15:22:07 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 15:11:15 GMT]]></title><description><![CDATA[<p dir="auto">Not to nitpick (okay, I am nitpicking), but both <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a>’s regexes would match some pretty strange ones.  They are good enough, assuming all data is reasonably valid.  But they can match some pretty strange bad data:</p>
<pre><code>X---        -- not ok, IMO
X-.-        -- not ok, IMO
X...1...    -- not ok, IMO
X1.2.3.4    -- not ok, IMO
</code></pre>
<p dir="auto">Adding some additional tests</p>
<pre><code>X1          -- ok
X-1         -- ok
X1.0        -- ok
X+1.0       -- ok
X-1.1       -- ok
X.1         -- ok or not? 
X+.1        -- ok or not? 
X-.1        -- ok or not? 
X1.         -- ok or not? 
</code></pre>
<p dir="auto">The regex <code>X([-+]?[0-9]+(?:[.](?=[0-9]))?[0-9]*)</code>  seems to match all the “ok” except the “ok or not?” rows.<br />
It’s fully explained by <a href="http://regexr.com/3unfp" rel="nofollow ugc">regexr.com/3unfp</a>, but in brief: it finds</p>
<ul>
<li>literal X,</li>
<li>then 0 or 1 sign characters (+ or -)</li>
<li>then at least one digit,</li>
<li>then 0 or 1 decimal points (but <em>only</em> if it has at least one digit)</li>
<li>then any remaining digits</li>
</ul>
<p dir="auto">So, right now, mine won’t catch <code>X.1</code> or <code>X1.</code> (actually, it would match the <code>X1</code> from <code>X1.</code>)</p>
<ul>
<li>If you want it to capture the <code>X.1</code> family, change the first <code>[0-9]+</code> to <code>[0-9]*</code>.</li>
<li>If you want it to catch the full <code>X1.</code>, then change <code>(?:[.](?=[0-9]))?</code> to the much simpler <code>\.?</code></li>
</ul>
<p dir="auto">For numerical regular expressions, it’s hard to be perfect: mine matches the <code>X1.2</code> of <code>X1.2.3.4</code>.  It would take some effort to avoid matching that one.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34488</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34488</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 30 Aug 2018 15:11:15 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 14:46:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeremy-h" aria-label="Profile: Jeremy-H">@<bdi>Jeremy-H</bdi></a></p>
<blockquote>
<p dir="auto">the X value could just as easily be a negative number</p>
</blockquote>
<p dir="auto">If the number can be negative, then you’d want to adjust my find expression to be <code>X([-0-9.]+)</code> if you are going my route.</p>
<blockquote>
<p dir="auto">if I only want to match and replace a certain part of as file, can I just select the code I want to change and only change that?</p>
</blockquote>
<p dir="auto">The <strong>Replace</strong> tab has an <strong>In selection</strong> checkbox so you can tick that to limit the replacement to only selected text.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34486</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34486</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Thu, 30 Aug 2018 14:46:47 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 14:41:59 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for reminding me Terry.  Yes the X value could just as easily be a negative number.  I meant the add that as a possibility.  Also, if I only want to match and replace a certain part of as file, can I just select the code I want to change and only change that?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34485</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34485</guid><dc:creator><![CDATA[Jeremy H]]></dc:creator><pubDate>Thu, 30 Aug 2018 14:41:59 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 14:11:36 GMT]]></title><description><![CDATA[<p dir="auto">Wow, thanks guys! I will try out these solutions today.  You guys rock!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34484</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34484</guid><dc:creator><![CDATA[Jeremy H]]></dc:creator><pubDate>Thu, 30 Aug 2018 14:11:36 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 11:59:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a></p>
<p dir="auto">I’m not one for “regex golfing”, but maybe this shorter one is clearer to the OP for learning/building upon, however, it does make the matching less restrictive, so depending on the OP’s surrounding data it may not be as good:</p>
<p dir="auto"><strong>Find what</strong> zone: <code>X([0-9.]+)</code><br />
<strong>Replace with</strong> zone: <code>X[#501*\1]</code><br />
<strong>Search mode</strong>: Regular expression</p>
<p dir="auto">Here’s an explanation of how it works:</p>
<h4>THE FIND EXPRESSION:</h4>
<p dir="auto"><code>X([0-9.]+)</code></p>
<ul>
<li>[Match the character “X” literally (case sensitive)][1] <code>X</code></li>
<li>[Match the regex below and capture its match into backreference number 1][2] <code>([0-9.]+)</code>
<ul>
<li>[Match a single character present in the list below][3] <code>[0-9.]+</code>
<ul>
<li>[Between one and unlimited times, as many times as possible, giving back as needed (greedy)][4] <code>+</code></li>
<li>[A character in the range between “0” and “9”][3] <code>0-9</code></li>
<li>[The literal character “.”][1] <code>.</code></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>THE REPLACE EXPRESSION:</h4>
<p dir="auto"><code>X[#501*\1]</code></p>
<ul>
<li>[Insert the character string “X[#501*” literally][1] <code>X[#501*</code></li>
<li>[Insert the text that was last matched by capturing group number 1][5] <code>\1</code></li>
<li>[Insert the character “]” literally][1] <code>]</code></li>
</ul>
<p dir="auto">Created with <a href="http://www.regexbuddy.com/" rel="nofollow ugc">RegexBuddy</a></p>
<p dir="auto">[1]: <a href="http://www.regular-expressions.info/characters.html" rel="nofollow ugc">http://www.regular-expressions.info/characters.html</a><br />
[2]: <a href="http://www.regular-expressions.info/brackets.html" rel="nofollow ugc">http://www.regular-expressions.info/brackets.html</a><br />
[3]: <a href="http://www.regular-expressions.info/charclass.html" rel="nofollow ugc">http://www.regular-expressions.info/charclass.html</a><br />
[4]: <a href="http://www.regular-expressions.info/repeat.html" rel="nofollow ugc">http://www.regular-expressions.info/repeat.html</a><br />
[5]: <a href="http://www.regular-expressions.info/replacebackref.html" rel="nofollow ugc">http://www.regular-expressions.info/replacebackref.html</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/34479</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34479</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Thu, 30 Aug 2018 11:59:36 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 06:53:24 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, just noticed a typo. I had it working, but gave you a different version which doesn’t work.</p>
<p dir="auto">Correct Find What: <code>(G1 X|G2 X|Y0.34 X)([-\.0-9]+)</code></p>
<p dir="auto">Everything else correct.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34471</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34471</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Thu, 30 Aug 2018 06:53:24 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace on Thu, 30 Aug 2018 06:19:49 GMT]]></title><description><![CDATA[<p dir="auto">Try the following regex.</p>
<p dir="auto">Find what: <code>^(G1 X|G2 X|Y0.34 X)([.-0-9]+)</code><br />
Replace with: <code>\1\[#501\*\2\]</code></p>
<p dir="auto">So Ctrl-H (Replace option), add the two fields as shown above. Select Wrap around and the search mode needs to be “Regular Expression”.</p>
<p dir="auto">The replacement works wells in your example, hopefully it does so as well with the rest of the file. Please note I’ve also catered for the possibility of the original number (that will appear behind the *) could be a negative (some coord systems use -ve and +ve coordinate numbers). If not the case here, then you could remove the first “-” in the block [.-0-9].</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34470</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34470</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Thu, 30 Aug 2018 06:19:49 GMT</pubDate></item></channel></rss>