<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=16342&amp;type=atom" />
	<updated>2021-05-11T20:51:17Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16342</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147817#p147817" />
			<content type="html"><![CDATA[<p>На самом деле не совсем:<br /></p><div class="codebox"><pre><code>File := &quot;Text.txt&quot;
Text=
(

Всем привет! 

   Я Олег

Я помыл своего кота.

)
FileDelete, % File
FileAppend, % Text, % File

FileRead, Out, Text.txt
MsgBox, 0, Исходный текст:, % Out
Out2 := RegExReplace(Out, &quot;m)^\s+&quot;)
MsgBox, 0, Обработанный текст:, % &quot;|&quot; Out2 &quot;|&quot;
Return</code></pre></div><p>Как видно, удалились пробелы из второй непустой строки, что не входило в задачу, и последний лишний перенос строки остался.<br />А вот так вообще не будет удалять:<br /></p><div class="codebox"><pre><code>text =
(

Всем привет! 

Я Олег

Я помыл своего кота.

)
FileOpen(&quot;text.txt&quot;, &quot;w&quot;).Write(text)
FileRead, textFromFile, text.txt
MsgBox, % &quot;|&quot; RegExReplace(textFromFile, &quot;m)^\s+&quot;) &quot;|&quot;</code></pre></div><p>Всё зависит, какой вариант переноса строк используется, `r`n или `n.<br />Для обоих вариантов есть опция `a:<br /></p><div class="codebox"><pre><code>text =
(

Всем привет! 

Я Олег

Я помыл своего кота.

)
FileOpen(&quot;text.txt&quot;, &quot;w&quot;).Write(text)
FileRead, textFromFile, text.txt
MsgBox, % &quot;|&quot; RegExReplace(textFromFile, &quot;`am)^\s+&quot;) &quot;|&quot;</code></pre></div><p>Но так последний перенос строки тоже не удалился.<br />Тут всё немного хитрее.<br /></p><div class="codebox"><pre><code>text =
(

Всем привет! 

   Я Олег

Я помыл своего кота.

)
MsgBox, % &quot;|&quot; . RegExReplace(text, &quot;^(\h*(\R|$))+|\R\h*(?=\R|$)&quot;) . &quot;|&quot;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-11T20:51:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147817#p147817</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147814#p147814" />
			<content type="html"><![CDATA[<p>Очень интересно почему так вышло.<br />Up: Ну так чтение из файла иную кодировку имеет и пустые строки удаляет.</p><div class="codebox"><pre><code>File := &quot;Text.txt&quot;	; Файл для чтения строк.

IfNotExist, % File	; Проверить его существование, если нет - создать и записать строки:
{
 Text=
 (

Всем привет! 

Я Олег

Я помыл своего кота.
 )
 FileAppend,% Text, % File
}


FileRead, Out, Text.txt		; Прочитать файл.
Return


F2::
MsgBox, 0, Исходный текст:, % Out
Out2 := RegExReplace(Out, &quot;m)^\s+&quot;)
MsgBox, 0, Обработанный текст:, % Out2
Return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2021-05-11T19:31:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147814#p147814</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147812#p147812" />
			<content type="html"><![CDATA[<p><strong>__Михаил__</strong><br /></p><div class="codebox"><pre><code>out =
(

Всем привет! 

Я Олег

Я помыл своего кота.

)
MsgBox, % &quot;|&quot; RegExReplace(out, &quot;m)^\s+&quot;, &quot;&quot;) &quot;|&quot;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-11T19:10:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147812#p147812</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147811#p147811" />
			<content type="html"><![CDATA[<p>Мне не помогло. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br /></p><div class="codebox"><pre><code>out =
(

Всем привет! 

Я Олег

Я помыл своего кота.

)
MsgBox, % &quot;|&quot; RegExReplace(out, &quot;m) \R(\R)*+&quot;, &quot;`n&quot;) &quot;|&quot;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-11T19:09:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147811#p147811</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147810#p147810" />
			<content type="html"><![CDATA[<p>Удалось таким способом:<br /></p><div class="codebox"><pre><code>Out := RegExReplace(out, &quot;m)^\s+&quot;, &quot;&quot;)</code></pre></div><p>Т.е. пробел после опции &#039;m)&#039; не нужен.</p>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2021-05-11T19:07:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147810#p147810</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147809#p147809" />
			<content type="html"><![CDATA[<p><strong>__Михаил__</strong></p><p>Понял. Спасибо<br />Это мне и правда помогло.<br /></p><div class="codebox"><pre><code>RegExReplace(out, &quot;m) \R(\R)*+&quot;, &quot;`n&quot;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Clannad5]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39853</uri>
			</author>
			<updated>2021-05-11T18:47:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147809#p147809</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147808#p147808" />
			<content type="html"><![CDATA[<p>Вроде как нужно использовать &#039;m) &#039; для мульти-строчного текста.<br />Примерный шаблон (не работает как нужно):</p><div class="codebox"><pre><code>File := &quot;Text.txt&quot;	; Файл для чтения строк.

IfNotExist, % File	; Проверить его существование, если нет - создать и записать строки:
{
 Text=
 (

Всем привет! 

Я Олег

Я помыл своего кота.
 )
 FileAppend,% Text, % File
}

FileRead, out, Text.txt		; Прочитать файл.
Return

F2::
out := RegExReplace(out, &quot;m) \s+&quot;, &quot;.&quot;)
MsgBox, % out
Return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2021-05-11T18:42:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147808#p147808</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: не понимаю как работать с RegExReplace в Ahk]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147807#p147807" />
			<content type="html"><![CDATA[<p>Есть файл Text.txt:</p><div class="codebox"><pre><code>
Всем привет! 

Я Олег

Я помыл своего кота.
</code></pre></div><p>Есть команда в Ahk:</p><div class="codebox"><pre><code>
FileRead, out, Text.txt
out := RegExReplace(out, &quot;\s+$&quot;, &quot;&quot;)
</code></pre></div><p>Результат следующий:</p><div class="codebox"><pre><code>
Всем привет! 

Я Олег

Я помыл своего кота.
</code></pre></div><p>То есть, результат не изменился.<br />Пробую тоже самое на <a href="https://regex101.com/">https://regex101.com/</a><br />Вот что выходит: <a href="https://regex101.com/r/708VHz/1">https://regex101.com/r/708VHz/1</a></p><p>Вопрос: Это с AHK что-то не так или я делаю что-то не так?</p><p>Цель: Удалить пустые строки, которые могут включать как пробелы так и табуляции.</p>]]></content>
			<author>
				<name><![CDATA[Clannad5]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39853</uri>
			</author>
			<updated>2021-05-11T17:29:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147807#p147807</id>
		</entry>
</feed>
