removing double blank lines using regex

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
partof
Posts: 110
Joined: 16 Jan 2016, 08:38

removing double blank lines using regex

09 Oct 2018, 09:40

I don't understand why this code isn't working since the regex works fine (I need to change the double/tripple/... blank line, into a single).

Code: Select all

[code=autohotkey file=Untitled.ahk]^!Space::
	clipboard =
	Send, ^a
	Send, ^c
	ClipWait
	clipboard := RegExReplace(clipboard, "^[\r\n]{2,}","\n")
	sleep 100
	Send, ^v
	return
[/code]

Any idea what could be wrong?
partof
Posts: 110
Joined: 16 Jan 2016, 08:38

Re: removing double blank lines using regex

09 Oct 2018, 10:16

It's getting closer: this one removes the multiple blank lines *when the text contains line breaks*, but... it adds an extra line when the text doesn't contain line break... Crazy...

Code: Select all

^!Space::
	clipboard =
	Send, ^a
	Send, ^c
	ClipWait
	clipboard := RegExReplace(clipboard,"\v\v+","`n`n") ; v find vertical tab char
	sleep 100
	Send, ^v
	return
Last edited by partof on 09 Oct 2018, 13:14, edited 1 time in total.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: removing double blank lines using regex

09 Oct 2018, 10:40

Code: Select all

ClipBoard := RegExReplace(ClipBoard, "\R(?=\R{2,})")
; or
ClipBoard  := RegExReplace(ClipBoard , "\R\R\K\R+")
partof
Posts: 110
Joined: 16 Jan 2016, 08:38

Re: removing double blank lines using regex

09 Oct 2018, 13:06

Bravo AlphaBravo! Oh I'm so happy, thank you so much!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: arrondark, mikeyww, RussF, science2002 and 86 guests