<?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[Replace entire line based on first characters]]></title><description><![CDATA[<p dir="auto">Hello, how do I replace every line that starts with <strong>“X”: 50.</strong> with <strong>“X”: 50.0,</strong><br />
There are random numbers after every <strong>“X”: 50.</strong> and I want them to be set to <strong>0</strong></p>
<p dir="auto">Here is the document I’m working on (I’ve removed some lines to fit in the post). I’ve tried doing it one by one, but I’m hoping someone could help me find a shortcut.</p>
<p dir="auto">{<br />
“Events”: [<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseDown”,<br />
“Timestamp”: 603,<br />
“X”: 50.0,<br />
“Y”: 79.61000061035056<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 683,<br />
“X”: 50.0,<br />
“Y”: 79.50000213623050<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 687,<br />
“X”: 50.0,<br />
“Y”: 78.93000030507578<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 699,<br />
“X”: 50.0,<br />
“Y”: 78.26000213623050<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 703,<br />
“X”: 50.0,<br />
“Y”: 76.9000015258789<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 716,<br />
“X”: 50.0,<br />
“Y”: 75.26000213623050<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 719,<br />
“X”: 50.0,<br />
“Y”: 73.0<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 730,<br />
“X”: 50.0,<br />
“Y”: 71.0<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 891,<br />
“X”: 50.880001068115234,<br />
“Y”: 41.540000915527344<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 895,<br />
“X”: 50.77000045776367,<br />
“Y”: 40.66999816894531<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 906,<br />
“X”: 50.720001220703125,<br />
“Y”: 39.5099983215332<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 911,<br />
“X”: 50.61000061035056,<br />
“Y”: 38.55099923706055<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 923,<br />
“X”: 50.61000061035056,<br />
“Y”: 38.060001373291016<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 926,<br />
“X”: 50.61000061035056,<br />
“Y”: 37.38999938965044<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 939,<br />
“X”: 50.5,<br />
“Y”: 36.61000061035056<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 943,<br />
“X”: 50.45000076293945,<br />
“Y”: 35.84000015258789<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 955,<br />
“X”: 50.34000015258789,<br />
“Y”: 35.15999985041211<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 959,<br />
“X”: 50.34000015258789,<br />
“Y”: 34.5000016784668<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 971,<br />
“X”: 50.34000015258789,<br />
“Y”: 33.709999084502656<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 975,<br />
“X”: 50.34000015258789,<br />
“Y”: 33.0<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 986,<br />
“X”: 50.34000015258789,<br />
“Y”: 32.16999816894531<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 991,<br />
“X”: 50.34000015258789,<br />
“Y”: 31.399999618530273<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 1003,<br />
“X”: 50.34000015258789,<br />
“Y”: 30.719999313354502<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 1007,<br />
“X”: 50.34000015258789,<br />
“Y”: 30.0<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 1019,<br />
“X”: 50.34000015258789,<br />
“Y”: 29.3700008392334<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 1023,<br />
“X”: 50.34000015258789,<br />
“Y”: 28.690000534057617<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseMove”,<br />
“Timestamp”: 1886,<br />
“X”: 50.95000076293945,<br />
“Y”: 6.659999850412109<br />
},<br />
{<br />
“Delta”: 0,<br />
“EventType”: “MouseUp”,<br />
“Timestamp”: 1950,<br />
“X”: 50.95000076293945,<br />
“Y”: 6.659999850412109<br />
}<br />
]<br />
}</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/25332/replace-entire-line-based-on-first-characters</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 15:05:45 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/25332.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 09 Jan 2024 03:08:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Replace entire line based on first characters on Wed, 10 Jan 2024 08:25:46 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/30029">@silvermew22</a>, <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/5329">@mkupper</a>, <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26710">@mark-olson</a> and <strong>All</strong>,</p>
<p dir="auto">I suppose that the following version should be <strong>better</strong> as it reduces the replacements to the syntaxes like <strong><code>50.880001068115234</code></strong> or <strong><code>50.5</code></strong> <strong>only</strong> !</p>
<p dir="auto">SEARCH <strong><code>(?-i)((?&lt;!\\)"X"\s*:\s*50\.)(?!0,)\d+</code></strong></p>
<p dir="auto">Replace <strong><code>${1}0</code></strong></p>
<hr />
<p dir="auto">Now, in order to <strong>only</strong> get modifications, in the <strong>right</strong> <strong><code>"Events"</code></strong> array, we could use this version :</p>
<p dir="auto">SEARCH <strong><code>(?-i)(?:"Events"|(?!\A)\G)(?s:(?!\x5D).)*?\K((?&lt;!\\)"X"\s*:\s*50\.)(?!0,)\d+</code></strong></p>
<p dir="auto">REPLACE <strong><code>${1}0</code></strong></p>
<p dir="auto">So :</p>
<ul>
<li>Paste your <strong><code>JSON</code></strong> file <em>OR</em> the example, below, in a <strong>new</strong> tab</li>
</ul>
<pre><code class="language-diff">{
"Tests": [
{
"Delta": 0,
"EventType": "MouseDown",
"Timestamp": 603,
"X": 50.0,
"Y": 79.61000061035056
},
{
"Delta": 0,
"EventType": "MouseMove",
"Timestamp": 891,
"X": 50.880001068115234,
"Y": 41.540000915527344
},
{
"Delta": 0,
"EventType": "MouseMove",
"Timestamp": 939,
"X": 50.5,
"Y": 36.61000061035056
},
]
},
{
"Events": [
{
"Delta": 0,
"EventType": "MouseDown",
"Timestamp": 603,
"X": 50.0,
"Y": 79.61000061035056
},
{
"Delta": 0,
"EventType": "MouseMove",
"Timestamp": 683,
"X": 50.0,
"Y": 79.50000213623050
},
{
"Delta": 0,
"EventType": "MouseMove",
"Timestamp": 891,
"X": 50.880001068115234,
"Y": 41.540000915527344
},
{
"Delta": 0,
"EventType": "MouseMove",
"Timestamp": 939,
"X": 50.5,
"Y": 36.61000061035056
},
{
"Delta": 0,
"EventType": "MouseUp",
"Timestamp": 1950,
"X": 50.95000076293945,
"Y": 6.659999850412109
}
]
}
</code></pre>
<ul>
<li>
<p dir="auto">Move the caret to the <strong>very beginning</strong> of the file ( Very <em>IMPORTANT</em> )</p>
</li>
<li>
<p dir="auto">Open the <strong>Replace</strong> dialog ( <strong><code>Ctrl + H</code></strong> )</p>
</li>
<li>
<p dir="auto"><strong>Untick</strong> all the <strong>box</strong> options</p>
</li>
<li>
<p dir="auto">Click <strong>once</strong> on the <strong><code>Replace All</code></strong> button</p>
</li>
</ul>
<p dir="auto">Voila ! There were <strong>only</strong> <strong><code>3</code></strong> replacements in the <strong>unique</strong> <strong><code>"Events"</code></strong> array… and <strong>none</strong> in the <strong><code>"Tests"</code></strong> array !</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91890</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91890</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Wed, 10 Jan 2024 08:25:46 GMT</pubDate></item><item><title><![CDATA[Reply to Replace entire line based on first characters on Tue, 09 Jan 2024 21:54:01 GMT]]></title><description><![CDATA[<p dir="auto">One change I would make to the regex of mkupper, if you’re going to use regular expressions:<br />
replace <code>(?-i)((?&lt;!\\)"X"\s*:\s*50\.)\d*</code> with <code>${1}0</code></p>
<p dir="auto">Essentially the same, except:</p>
<ul>
<li>I get rid of the <code>^\s*</code> before the “X” key, and allow any amount of whitespace between the key and the colon, because <strong>JSON-parsing regexes should not make <em>any</em> assumptions about formatting.</strong></li>
<li>The <code>(?&lt;!\\)</code> before the open quote is just to guard against any weirdness with escaped quotes</li>
<li>I use the alternate <code>${1}</code> syntax to get the first capture group in the replacement regex, because I like that syntax better.</li>
</ul>
]]></description><link>https://community.notepad-plus-plus.org/post/91884</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91884</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Tue, 09 Jan 2024 21:54:01 GMT</pubDate></item><item><title><![CDATA[Reply to Replace entire line based on first characters on Tue, 09 Jan 2024 19:18:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/5329">@mkupper</a> said in <a href="/post/91878">Replace entire line based on first characters</a>:</p>
<blockquote>
<p dir="auto">\1\x30</p>
</blockquote>
<p dir="auto">Thank you so much, it worked. You saved me hours of time.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91880</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91880</guid><dc:creator><![CDATA[SilverMew22]]></dc:creator><pubDate>Tue, 09 Jan 2024 19:18:18 GMT</pubDate></item><item><title><![CDATA[Reply to Replace entire line based on first characters on Tue, 09 Jan 2024 18:55:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/30029">@SilverMew22</a> said in <a href="/post/91864">Replace entire line based on first characters</a>:</p>
<blockquote>
<p dir="auto">Hello, how do I replace every line that starts with “X”: 50. with “X”: 50.0,<br />
There are random numbers after every “X”: 50. and I want them to be set to 0</p>
</blockquote>
<p dir="auto">Do it as a regular expression search/replace<br />
<strong>Search: <code>(?-i)^(\s*"X":\s*50\.)\d*</code><br />
Replace: <code>\1\x30</code></strong></p>
<p dir="auto">Parsing that from left to right:</p>
<ul>
<li><code>(?-i)</code> - Make this a case-sensitive search/replace so that “X” does not match “x”.</li>
<li><code>^</code> - Start at the beginning of a line.</li>
<li><code>(\s*"X":\s*50\.)</code> - This is a capture group as it’s inside the parentheses. It contains:</li>
<li><code>\s*</code> - Match zero or more spaces/tabs at the beginning of the line.</li>
<li><code>"X":\s*50\.</code> - Match the characters <code>"X":</code> followed by <code>\s*</code> zero or more spaces. followed by the characters <code>50.</code>.</li>
<li><code>\d*</code> - match zero or more digits</li>
</ul>
<p dir="auto">The replacement has:</p>
<ul>
<li><code>\1</code> - this is the contents of the first capture group and will be the leading spaces followed by the `“X”: 50.’ that was matched and stored in the capture group.</li>
<li><code>\x30</code> - This is an ASCII zero. I could have used a replacement of <code>\10</code> but that sure looks like a ten and so I used <code>\x30</code> instead of <code>0</code> to reduce the chances of confusion.</li>
</ul>
<p dir="auto">This will change a <code>50.</code> without any following digits into <code>50.0</code>. If you don’t desire that then this can be fixed.</p>
<p dir="auto">This also “replaces” <code>50.0</code> with <code>50.0</code> which is no change but it made the search/replace expression simpler.</p>
<p dir="auto">I decided to ignore the comma at the end of the “X” lines. If it’s there then it remains there.</p>
<p dir="auto">As <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26710">@Mark-Olson</a> noted, this should really be handled by something that is JSON aware. If by chance you have “X” elements inside of things other than the blocks you have in your example then those too will have a <code>50....</code> value changed to <code>50.0</code>.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91878</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91878</guid><dc:creator><![CDATA[mkupper]]></dc:creator><pubDate>Tue, 09 Jan 2024 18:55:57 GMT</pubDate></item><item><title><![CDATA[Reply to Replace entire line based on first characters on Tue, 09 Jan 2024 03:34:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/30029">@SilverMew22</a></p>
<p dir="auto">In the future, please wrap text samples inside of ``` so that they show up like this:</p>
<pre><code class="language-json">{"this is the proper way to display text": true}
</code></pre>
<p dir="auto">In any case, you are working with JSON. <a href="https://community.notepad-plus-plus.org/topic/25304/faq-parsing-and-editing-json-with-regex-is-a-bad-idea/2">Other people might suggest using regular expressions. This is a bad idea.</a></p>
<p dir="auto">I recommend installing <a href="https://github.com/molsonkiko/JsonToolsNppPlugin" rel="nofollow ugc">the JsonTools plugin</a> and running the following query: <code>@.Events[:].X = 50.0</code></p>
<p dir="auto">Once you run that query, every <code>X</code> value should be converted to <code>50.0</code>, and the document will also be pretty-printed.</p>
<p dir="auto">This query converts the <code>X</code> field of each element in the <code>Events</code> field of the root JSON to the number <code>50.0</code>. To learn more about the syntax of this query, I recommend reading <a href="https://github.com/molsonkiko/JsonToolsNppPlugin/blob/main/docs/RemesPath.md" rel="nofollow ugc">this documentation on the RemesPath query language</a>.</p>
<p dir="auto">That query assumes that the structure of the file is more or less as you showed it. If that query raises an error, I will need to know more about the structure of your JSON.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91865</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91865</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Tue, 09 Jan 2024 03:34:12 GMT</pubDate></item></channel></rss>