2

根据http://www.rebol.com/docs/core23/rebolcore-15.html

您可以使用 change/part 来解析和替换,但这不适用于我只是尝试替换块

<mytag > ... </mytag>

通过“我的字符串”

content:  {<mytag id="a" 111111111111111>
</mytag>
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
<mytag id="b" 22222222222222222>
</mytag>

<mytag id="c" 3333333333333>
</mytag>
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
<mytag id="d" 444444444444444>
</mytag>
}


mytag: [  to {<mytag} start: (
)
  thru {<mytag}
  to {id="} thru {id="} copy ID to {"} thru {"}
  to {</mytag>} 

  thru {</mytag>} 
  ending:

  (change/part start "mystring" ending)
  mark:
  (  write clipboard:// mark
  input)  
]

rule: [any mytag to end]

parse content rule
4

2 回答 2

3

我点你看看http://en.wikibooks.org/wiki/REBOL_Programming/Language_Features/Parse#Modifying_the_input_series

于 2010-04-13T21:22:28.173 回答
2

Ladislav 的建议是在不更改输入流的情况下解决它,这可能会出现性能问题并且更难调试。只需单独建立你的输出。例如

result: copy ""

mytag: [
  [
    copy text to {<mytag} (if text [append result text])
    thru {<mytag}
    to {id="} thru {id="} copy ID to {"} thru {"}
    thru {</mytag>} 
    (append result reform ["__" ID "__"])
  ]
  | 
  skip
]

rule: [any mytag to end]

parse content rule

result
于 2010-04-14T17:10:15.900 回答