Simpel Posted September 25, 2018 Posted September 25, 2018 (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 April 25, 2019 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) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
mikell Posted September 25, 2018 Posted September 25, 2018 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)
Simpel Posted September 26, 2018 Author Posted September 26, 2018 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) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
mikell Posted September 26, 2018 Posted September 26, 2018 (edited) 7 hours ago, Simpel said: Is my brain tricking me? No 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 September 26, 2018 by mikell
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now