【发布时间】:2020-06-28 17:10:13
【问题描述】:
我对 AHK 有点陌生,我写了一些脚本。但是对于我最新的脚本,我有点坚持使用 AHK 中的 REGEX。 我想报告我所做的文本结构。
为此我建立了一个系统:
- 以“.”结尾的句子是带有“-”的重要句子。 (变量“Vimportant”)但没有提到“Vanecdotes2”或“Vdelete2”cfr 的词。 4
- 以“.*”结尾的句子是轶事(变量“Vanecdotes1”),我在该点之后手动放置了一个星号。
- 以“.!”结尾的句子是不相关的句子,需要删除(变量“Vdelete1”),如果我在该点后面手动加了一个星号。
- 我要实现的一个额外选项是要在句子中检测单词,以便将句子自动添加到变量“Vanecdotes2”或“Vdelete2”中
一个随机的例子是这样的(我已经把!和*放在句子后面(为什么不重要),其中“获取”是我上面第 4 点的一个例子 op Vanecdotes2):
最后一次手术时间为 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.
所以变量中Regex的输出应该是
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 没有真正好的测试器,所以我首先在另一个正则表达式测试器中对其进行了测试,并计划稍后将其“翻译”为 AHK 代码。但它只是不起作用。 (所以我知道在下面的脚本中我使用 AHK 语言和非 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
对于“翻译为 AHK”,我尝试从工作(非 ahk)正则表达式 ^.*[.][*]\n 制作 ^.*\*'n。
【问题讨论】:
标签: regex report autohotkey