RegExReplace to remove lines off the top

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
robinson
Posts: 189
Joined: 12 Sep 2019, 20:28

RegExReplace to remove lines off the top

Post by robinson » 02 Jun 2023, 14:58

Hi, noob here.
How do you use RegExReplace to completely remove the first, say, 3 lines from a paragraph of text.
I tried this and it didn't work:

Code: Select all

:*?c:test:: {
	A_Clipboard:=("line 1`nline 2`nline 3`nline 4")
	A_Clipboard:=RegExReplace(A_Clipboard,"^.*$",,,3)
	Sleep(500)
	SendEvent("{LCtrl DOWN}{v DOWN}{v UP}{LCtrl UP}")         ; ^v
}
Another simple one probably, but I need a little help nonetheless.
Thanks!

teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: RegExReplace to remove lines off the top

Post by teadrinker » 02 Jun 2023, 15:36

Code: Select all

str := 'line 1`nline 2`nline 3`nline 4'
MsgBox str

lineCountToRemove := 3
MsgBox RegExReplace(str, '(\V*\R){' . lineCountToRemove . '}')

robinson
Posts: 189
Joined: 12 Sep 2019, 20:28

Re: RegExReplace to remove lines off the top

Post by robinson » 02 Jun 2023, 18:56

Thanks
but what if the first line doesn't have a vertical whitespace (\V) character before it?

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: RegExReplace to remove lines off the top

Post by boiler » 02 Jun 2023, 19:48

robinson wrote: but what if the first line doesn't have a vertical whitespace (\V) character before it?
The first line in the demo script doesn't have a vertical whitespace character before it, and it works (it would be strange if he posted a script where chosen case didn't even work), so why would you ask that? And \V doesn't mean vertical whitespace character. It means any character except a vertical whitespace character. You're confusing it with \v. And even if it did mean that, the * quantifier means zero or more of what precedes it.

robinson
Posts: 189
Joined: 12 Sep 2019, 20:28

Re: RegExReplace to remove lines off the top

Post by robinson » 02 Jun 2023, 21:14

Oh right, sorry I read it as \V.*\R

Post Reply

Return to “Ask for Help (v2)”