How to adapt this Simple script to RegEx format Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guill
Posts: 139
Joined: 09 Jun 2016, 22:00

How to adapt this Simple script to RegEx format

Post by Guill » 26 May 2022, 19:13

Hi guys,

I have this script, which I use to remove line breaks from continuous text in Notepad (and when it encounters a ".", "!", etc., it does not remove the end, but continues on).

It works, but I would like to know if I can make it do it faster using Regular Expressions or another method.

Code: Select all

Loop
{

Send {End}

Send {Shift Down}{Left}{Shift Up}
sleep 45
Send ^c^c
Send {Right}

If (Clipboard = a_space)
{
sleep 345
Send {End}{Del}
Return
}

If (Clipboard = "-")
{
Send {Del}{BS}
Return
}


If (Clipboard = "¬")
{
Send {Del}{BS}
Return
}

If (Clipboard = ":")
{
Send {Down}
Return
}

If (Clipboard = ".")
{
Send {Enter}{Down}
Return
}

If (Clipboard = "?")
{
Send {Enter}{Down}
Return
}

If (Clipboard = "!")
{
Send {Enter}{Down}
Return
}
Else
{
sleep 345
Send {End}{Space}{Del}
}
 If GetKeyState("Esc", "P")
Break
}
Return


User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: How to adapt this Simple script to RegEx format

Post by mikeyww » 26 May 2022, 20:46

You could copy the entire string (all text), and then work with it instead of just one character at a time. A series of :arrow: StrReplace may be good enough. Example

Guill
Posts: 139
Joined: 09 Jun 2016, 22:00

Re: How to adapt this Simple script to RegEx format

Post by Guill » 26 May 2022, 21:13

Thank you,

but I have two problems with this option:


1 How could I configure StringReplace to say delete "carriage return"?

"`r`n" doesn't work when I try it.


2 How could I say, for example, "delete the "-" that is only at the end of the line (and not everyone)?

The principal problem that I have is I want to delete "carriage return" and divided words by "-". I need the text without interruptions.

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: How to adapt this Simple script to RegEx format  Topic is solved

Post by mikeyww » 26 May 2022, 21:27

Code: Select all

F3::
str := RegExReplace(Clipboard, "m`a)-(\h*)$", "$1") ; Delete trailing hyphen
str := RegExReplace(str, "\R")                      ; Delete line break
SendInput {Text}%str%
Return

Guill
Posts: 139
Joined: 09 Jun 2016, 22:00

Re: How to adapt this Simple script to RegEx format

Post by Guill » 26 May 2022, 22:27

Thank you very much!
mikeyww wrote:
26 May 2022, 21:27

Code: Select all

F3::
str := RegExReplace(Clipboard, "m`a)-(\h*)$", "$1") ; Delete trailing hyphen
str := RegExReplace(str, "\R")                      ; Delete line break
SendInput {Text}%str%
Return

Post Reply

Return to “Ask for Help (v1)”