使用自动热键反转段落

Paragraph reversal using autohotkey

我有一段是这样的:

Rohit is a good boy.
He loves poetry.
He also sings.

我想这样反转段落:

.boy good a is Rohit
.poetry loves He
.sings also He

我有来自 this site 的这个工作脚本。

Loop, Parse, clipboard, %A_Space%
    new :=  RegExReplace(A_LoopField,"(.*)(\p{P})$","") A_Space new


Msgbox %    Trim(new,A_Space)

但是一次只能反转一行。我无法为我的目的修改脚本。

遍历行并创建一个包含当前行所有单词的数组,然后向后循环遍历单词。如果一个单词以标点字符结尾,则将其放在单词的开头。

text = 
(
Rohit is a good boy.
He loves poetry.
He also sings.
)

punctuationCharArray := [".",",","-",":",";","!","?"]
reversedText := ""
Loop, parse, text, `n, `r
{
    line := A_LoopField
    wordArray := StrSplit(line, " ")
    i := wordArray.MaxIndex()
    While (i>0) {
        rawWord := wordArray[i]
        punctuationChar := ""
        Loop % punctuationCharArray.MaxIndex() { ;check if the last character of the word is one of the specified punctuation chars
            If (SubStr(rawWord, -0) = punctuationCharArray[A_Index]) {
                punctuationChar := punctuationCharArray[A_Index]
                Break
            }
        }
        word := (punctuationChar ? SubStr(rawWord, 1, -1) : rawWord) ;if there is a punctuation char in the end, omit that
        reversedText .= punctuationChar . word . " " ;add the current (punctuation char), word and a space to the output text variable.
        i--
    }
    reversedText .= "`r`n" ;add a new line
}
MsgBox % reversedText

输出:

.boy good a is Rohit
.poetry loves He
.sings also He

下一步也是反转括号。