REGEX-自动文本选择和重构

REGEX-自动文本选择和重构,regex,report,autohotkey,Regex,Report,Autohotkey,我对AHK有点陌生,我写了一些脚本。但在我的最新剧本中,我有点被AHK中的REGEX卡住了。 我想把我所做的一个文本结构做一个报告 为此,我设置了一个系统: 以“.”结尾的句子是带“-”的重要句子。(变量“Vimportant”),但不包含“Vanecdotes2”或“Vdelete2”cfr中提到的词语。四, 以“.*”结尾的句子是轶事(变量“Vanecdotes1”),我在这一点后手动加了一个星号 以“.”结尾的句子,是不相关的句子,需要删除(变量'Vdelete1'),如果我在该点后手动添

我对AHK有点陌生,我写了一些脚本。但在我的最新剧本中,我有点被AHK中的REGEX卡住了。 我想把我所做的一个文本结构做一个报告

为此,我设置了一个系统:

  • 以“.”结尾的句子是带“-”的重要句子。(变量“Vimportant”),但不包含“Vanecdotes2”或“Vdelete2”cfr中提到的词语。四,
  • 以“.*”结尾的句子是轶事(变量“Vanecdotes1”),我在这一点后手动加了一个星号
  • 以“.”结尾的句子,是不相关的句子,需要删除(变量'Vdelete1'),如果我在该点后手动添加了星号
  • 我想实现的另一个选项是在句子中检测单词,以便将句子自动添加到变量“Vanecdotes2”或“Vdelete2”
  • 一个随机的例子是这样的(我已经在句子后面加了!和*(为什么不重要),其中“获得”是我上面第4点的例子:

    最后一次程序于2019年8月19日进行

    Normal structure x1.!  
    Normal structure x2.!  
    Abberant structure x3, needs follow-up within 2 months.  
    Structure x4 is lower in activity, but still above p25.  
    Abberant structure x4, needs follow-up within 6 weeks.  
    Normal structure x5.  
    Good aqcuisition of x6.  
    
    所以变量中正则表达式的输出应该是

    Last procedure on 19/8/2019.  
    Normal structure x1.! --> regex  '.!' --> Vdelete1  
    Normal structure x2.! --> regex  '.!' --> Vdelete1  
    Abberant structure x3, needs follow-up within 2 months. --> Regex '.' = Vimportant  
    Structure x4 is lower in activity, but still above p25.* --> regex '.*' = Vanecdote1  
    Abberant structure x4, needs follow-up within 6 weeks. --> Regex '.' = Vimportant  
    Normal structure x5.! --> regex  '.!' --> Vdelete1  
    Good aqcuisition of x6. --> Regex 'sentence with the word acquisition' = Vanecdote2  
    
    输出应为:

    '- Last procedure on 19/8/2019.  
     - Abberant structure x3, needs follow-up within 2 months.  
     - Abberant structure x4, needs follow-up within 6 weeks.  
    
    . Structure x4 is lower inactivity, but still above p25.  
    . Good aqcuisition of x6.
    
    但是我在使用正则表达式时遇到了很多麻烦,特别是在选择以*或!结尾的句子时!。但也有排除标准,他们只是不想这么做

    因为AHT没有一个真正好的测试仪,我首先在另一个regex测试仪中测试了它,我计划稍后将其“翻译”为AHK代码。。但它就是不起作用。(因此,我知道在下面的脚本中,我在nonAHK正则表达式中使用了AHK语言,但我只是将to放在一起进行说明)

    这就是我现在拥有的:

    Send ^c  
    clipwait, 1000  
    Temp := Clipboard  
    Regexmatch(Temp, "^.*[.]\n(?!^.*\(Anecdoteword1|Anecdoteword2|deletewordX|deletewordY)\b.*$)", Vimportant)  
    Regexmatch(Temp, "^.*[.][*]\n")", Vanecdotes1) 
    Regexmatch(Temp, "^.*[.][!]\n")", Vdelete1)   
    Regexmatch(Temp, "^.*\b(Anecdoteword1|Anecdoteword2)\b.*$")", Vanecdotes2)  
    Regexmatch(Temp, "^.*\b(deletewordX|deletewordY)\b.*$")", Vdelete2)   
    Vanecdotes_tot := Vanecdotes1 . Vanecdotes2  
    Vdelete_tot := Vdelete1 . Vdelete2  
    Vanecdotes_ster := "* " . StrReplace(Vanecdotes_tot, "`r`n", "`r`n* ")  
    Vimportant_stripe := "- " . StrReplace(Vimportant, "`r`n", "`r`n- ")  
    Vresult := Vimportant_stripe . "`n`n" . Vanecdotes_ster  
    

    对于“translation to AHK”,我试图从工作(非AHK)正则表达式中生成
    ^.*\'n
    ^.[.][*]\n

    实际上没有AHK正则表达式。AHK几乎使用PCRE,除了。
    因此,不要试图将换行符
    \n
    转换为AHK换行符
    `n

    而且您的正则表达式中似乎有一些语法错误。不太确定那些额外的
    应该是什么。另外,你应该使用
    \.*.
    ,而不是使用
    \.\*.
    \
    与这些特定字符一起使用,以转义它们的正常功能(任何字符以及零和无限之间的匹配)。
    []
    是匹配该组中的任何字符,就像您想匹配
    *
    一样,您需要执行
    [.]

    似乎你有了使用捕获组的想法,但为了以防万一,这里有一个关于它们的最小示例:

    RegexMatch("TestTest1233334Test", "(\d+)", capture)
    MsgBox, % capture
    
    最后,关于你解决问题的方法,我建议逐行循环输入。这样会更好/更容易。使用例如
    这方面的最小示例也包括:

    inp := "
    (
    this is
    a multiline
    textblock
    we're going
    to loop
    through it
    line by line
    )"
    
    Loop, Parse, inp, `n, `r
        MsgBox, % "Line " A_Index ":`n" A_LoopField
    

    希望这有帮助。

    这是我到目前为止一直在做的事情,没有任何效果(我会在正则表达式工作时尝试建议的循环):^m:: 块输入,打开 鼠标、TempID、控件 WinActivate,ahk_id%TempID% 如果WinActive(“Pt”) 发送^c 克利普韦特,1000 温度:=剪贴板 Regexmatch(Temp,“(^(?:…\n)((?!PAX | PAC | normal | Geen)。)$”,Vimportant) Vimportant:=Vimportant.1 Regexmatch(Temp,“(^..*\n)”,Vanecdotes1_ster) Regexmatch(Temp,“(^..!\n)”,Vdelete1\u uitroep) Regexmatch(Temp,“(^.\b(PAX | PAC)\b.$)”,Vanecdotes2) Regexmatch(Temp,“(^.\b(normal | Geen)\b.$”,Vdelete2) Vanecdotes1:=StrReplace(Vanecdotes1_ster,“.”,“) Vdelete1:=StrReplace(Vdelete1_uitroep,“.!”,“) Vanecdotes_tot:=Vanecdotes 1.Vanecdotes 2 Vdelete_tot:=Vdelete1.Vdelete2 Vanecdotes_u u ster:=“”.StrReplace(Vanecdotes_u tot,“
    r
    n”,“
    r
    n*”) Vimportant_条带:=“-”.StrReplace(Vimportant,“
    r
    n”,“
    r
    n-”) Vresult:=VimImportant\u stripe。“
    n
    n”。Vanecdotes 剪贴板:=Vresult 发送^v
    return

    很抱歉,复制粘贴时我犯了一些错误(“复制粘贴”)。我真的不明白您所说的“所以不要试图将换行符\n转换为AHK换行符`n”是什么意思。我可以在AHK中使用\n正则表达式吗?那么两者的区别是什么呢?我一直在研究我的正则表达式,现在他们在研究测试器。(?=.[.]\n)((?!轶事WORD1 |轶事WORD2 |删除Wordx |删除Wordy)*$因此我将尝试让它在AHK中工作。谢谢你的循环提示,我会深入研究:)!