我是autohotkey的新手,包括活动在内的任何代码:)我想从下面的示例haystack中提取一些部分,并将它们列在一个消息框中,并将外观顺序列为一个列表(如果找到一个项目多于一个将只列出一次,如果它使事情变得更容易,它们并排显示没有其他列表项放在相同的列表项之间)
我的样本干草堆:
Aliquam erat volutpat。 Lorem ipsum dolor坐下来,精致的adipistur elit。整数元素erat vitae urna pellentesque perm-anen-t1 condimentum。 Curabitur vestibulum vehicula perm-anen-t1 porttitor。 Ut ac tellus et tellus 主持人ornare。 Aliquam volutpat purus in augue sagittis,eget bibendum lacus cursus。简历lorem ultrices,sollicitudin prot-esto-r7 nunc non,fringilla erat。车辆利奥的Suspendisse qual-ifie-d6 。 Mauris imperdiet augue nec erat suscipit,eget aliquet nunc auctor。 Sed felis eros,dictum non tincidunt ac,tempus et nunc。
Mauris vehicula auto-moti-v9 molestie fermentum。 Morbi consectetur eros eget erat auto-moti-v9 aliquet,non dictum ipsum auto-moti-v9 sodales。 Duis scelerisque mi非interdum condimentum。
Vivamus rutrum neque nunc,consequat porta susp-ende-d7 urna vehicula ac。 Donec et tristique massa。 Suspendisse格言 在dui posuere condimentum。 Etiam eleifend pharetra tortor,nec mollis magna congue at。 Mauris libero nisi,posuere numbe-r1fi-t3 坐在amet velit sit amet,consectetur scelerisque nulla。 Sem中的Maecenas elementum purus lacinia,sit amet facilisis arcu ornare。 Donec numbe-r1fi-t3 tempus dignissim lacinia。 Pellentesque lacinia imperdiet quam,eu rutrum arcu。 Maecenas et est eu nibh suscipit vulputate nec quis massa。 Vestibulum ante ipsum faucibus orci luctus et ultrices posuere cubilia Curae; Aenean eu sagittis orci。整数 未接受的 noven-ber1-25 tincidunt。 Vivamus vel venenatis noven-ber1-25 nibh。 Quisque pharetra orci id pharetra laoreet。 Phasellus augue enim,tincidunt noven-ber1-25 pellentesque mi ac,fringilla auctor orci。
我想要的清单:
1. perm-anen-t1
2. prot-esto-r7
3. qual-ifie-d6
4. auto-moti-v9
5. susp-ende-d7
6. numbe-r1fi-t3
7. noven-ber1-25
我尝试了loop, RegexMatch, RegexReplace, InStr
等但无法管理。在教程中它讨论了一个数组,但是当我使用RegexMatch
时,match1列为正确但匹配2为空。如果可以使用Regular Expressions
解决此问题,那将非常有用。
答案 0 :(得分:0)
src:="Aliquam erat volutpat. Lorem ipsum dolor sit amet, consectetur "
. "adipiscing elit. Integer elementum erat vitae urna pellentesque "
. "perm-anen-t1 condimentum. Curabitur vestibulum vehicula perm-anen-t1 "
. "porttitor. Ut ac tellus et tellus auctor ornare. Aliquam volutpat purus "
. "in augue sagittis, eget bibendum lacus cursus. In vitae lorem ultrices, "
. "sollicitudin prot-esto-r7 nunc non, fringilla erat. Suspendisse "
. "qual-ifie-d6 at vehicula leo. Mauris imperdiet augue nec erat suscipit, "
. "eget aliquet nunc auctor. Sed felis eros, dictum non tincidunt ac, tempus "
. "et nunc.`r`nMauris vehicula auto-moti-v9 molestie fermentum. Morbi "
. "consectetur eros eget erat auto-moti-v9 aliquet, non dictum ipsum "
. "auto-moti-v9 sodales. Duis scelerisque mi non interdum condimentum.`r"
. "`nVivamus rutrum neque nunc, consequat porta susp-ende-d7 urna vehicula "
. "ac. Donec et tristique massa. Suspendisse dictum est at dui posuere "
. "condimentum. Etiam eleifend pharetra tortor, nec mollis magna congue at. "
. "Mauris libero nisi, posuere numbe-r1fi-t3 sit amet velit sit amet, "
. "consectetur scelerisque nulla. Maecenas elementum purus in sem lacinia, "
. "sit amet facilisis arcu ornare. Donec numbe-r1fi-t3 tempus dignissim "
. "lacinia. Pellentesque lacinia imperdiet quam, eu rutrum arcu. Maecenas et "
. "est eu nibh suscipit vulputate nec quis massa. Vestibulum ante ipsum "
. "primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean "
. "eu sagittis orci. Integer consequat nec ligula non noven-ber1-25 "
. "tincidunt. Vivamus vel venenatis noven-ber1-25 nibh. Quisque pharetra "
. "orci id pharetra laoreet. Phasellus augue enim, tincidunt noven-ber1-25 "
. "pellentesque mi ac, fringilla auctor orci.", pattern:="O)(\S*-\w*-\S*)"
MsgBox, % 262 . ((retResult:=SomeFunc(src, pattern)) ? 208:160)
, % retResult ? "Result:":"Oops!"
, % retResult ? RTrim(retResult, "`n"):"No matches"
; , % (retResult ? 3:0) . .5
SomeFunc(p*)
{
Static a:=[]
Local oVar:=cond:=outList:=""
While, RegExMatch(p.1, p.2, oVar, oVar.Pos(1) ? oVar.Pos(1)+oVar.Len:1)
{
Loop, % ObjMaxIndex(a)
cond:=False
Until, cond:=(a[A_Index]=oVar.Value)
`(!cond) And a[A_Index]:=oVar.Value
}
For k, v In a
outList.=(A_Index<=9 ? "0"A_Index:A_Index)". "v "`n"
Return, outList
}