Jump to content

Recommended Posts

Posted (edited)

Hi,

I'm trying to replace line breaks. But when there are two or more of them keep them. At the end it should reformat copied text with unwanted line breaks. This is my code:

#include <MsgBoxConstants.au3>
;~ Local $sText = ClipGet()
Local $sText = "asd" & @CRLF & "asd" & @CRLF & "asd" & @CRLF & "asd" & @CRLF & "asd" & @CRLF & @CRLF & "asd" & @CRLF & "asd" & @CRLF & "asd" & @CRLF & "asd" & @CRLF & "asd" & @CRLF & @CRLF & "asd"
MsgBox($MB_TOPMOST, "Original", $sText)
Local $sRegexKillEnters = "(?m)(?<=\V)\v(?!\v|\h\h|\t)" ; (first all but Enter)Enter(but not if Enter or 2 Spaces or a Tab - if one wrote a list)
$sText = StringRegExpReplace($sText, $sRegexKillEnters, " ")
MsgBox($MB_TOPMOST, "Kill Enters", $sText & @CRLF & @CRLF & "Extended: " & @extended)

I would expect:

asd asd asd asd asd

asd asd asd asd asd

asd

but get no error code and this:

asd
asd
asd
asd
asd

asd
asd
asd
asd
asd

asd

It works at regex101.com with flavour pcre: https://regex101.com/r/aTmV2T/1 but @AZJIO RegExp-Tester gives @Extended = 11.

What is my mistake? Simpel

Edited by Simpel
[Solved]
SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Posted
1 hour ago, Simpel said:

What is my mistake

\v matches a single vertical space, and in @crlf there are 2
Your expression works if you replace the \v  by \R (any newline sequence)

(?<=\V)\R(?!\v|\h\h|\t)

 

 

Posted

Curious. I had the feeling there was a slightly other answer that I read and then I left work. On my walk home I came to the solution that CR and LF are two characters and because of that the regex is failing. (Regex101.com seems to convert both characters to one while pasting.)

Now I see another part of code. (I remember some snippet with “SKIP” but I’m not sure.) Nevertheless I try your code tomorrow.

The part with |\h\h|\t is in advance (necessary for not deleting line breaks if someone made a list) and not needed here. (I remember a question about that. Question is not here any more. Funny. Is my brain tricking me?)

Regards, Simpel

P.S. Think I have to replace the second \v by \R too.

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Posted (edited)
7 hours ago, Simpel said:

Is my brain tricking me?

No  :D
My first message proposed a different pattern but didn't answer your question, reason why I changed it
This pattern is an alternative way to get the same result, something like this

Local $sRegexKillEnters = "\R(?|\R+|\h\h|\t)(*SKIP)(*F)|\R"

 

Edited by mikell

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...