我有以下解析問題。在下面的第一個示例文本中,解析將在找到文本中的部分時碰到兩個命令塊。使用更改命令(Rebol2)時解析問題
下面試試(Rebol 2)。
sample-text: {<a href="javascript:gotoURL('displayContent.aspx?contentID=9&language=english#Deferred-member');">deferred member</a>}
remove-anchors: func [sample-text][
parse sample-text[
some [
to {<a href="javascript:gotoURL('displayContent.aspx?contentID=9}
begin:
thru {);">}
ending:
(print "Command 1 executed")
to "<"
begin:
thru ">"
ending:
(print "Command 2 executed")
]
]
return sample-text
]
結果:
remove-anchors sample-text
Command 1 executed
Command 2 executed
然而,如果我插入命令,預計以除去它找到的文本的變化/部件部分,所述第一次更改/部分執行,但看起來分析命令的第二部分停止,因爲第二個執行塊沒有觸發。
sample-text: {<a href="javascript:gotoURL('displayContent.aspx?contentID=9&language=english#Deferred-member');">deferred member</a>}
remove-anchors: func [sample-text][
parse sample-text[
some [
to {<a href="javascript:gotoURL('displayContent.aspx?contentID=9}
begin:
thru {);">}
ending:
(print "Command 1 executed" change/part begin "" ending) ;<<----- change
to "<"
begin:
thru ">"
ending:
(print "Command 2 executed" change/part begin "" ending) ;<<----- change
]
]
return sample-text
]
結果:
remove-anchors sample-text
Command 1 executed
== "deferred member</a>"
注意第二個命令似乎沒有出現打印不執行和解析未完成同時執行。
因爲我有多個不同類型的我試圖刪除HTML的這些作品,並多次出現在同一文本文本鏈接,我想通PARSE是正確的解決方案。
任何人都可以看到我在做什麼錯?如果你使用這個
remove-anchors: func [sample-text][
parse sample-text[
some [
to {<a href="javascript:gotoURL('displayContent.aspx?contentID=9}
begin:
thru {);">}
ending:
(print "Command 1 executed" change/part begin "" ending)
:begin ; note this
to "<"
begin:
thru ">"
ending:
(print "Command 2 executed" change/part begin "" ending)
]
]
return sample-text
]
說明
感謝sqlab。這解決了這個問題。 – Brock 2014-09-10 18:30:12