这样的XML文件有一个片段:
"...<id>90,123</id>...<id>190</id>...<id>123,90</id>...
<id>123,90,123</id>...<id>901</id>"
我想将所有数字90替换为另一个数字,例如100.使用replace/all
会破坏190和901之类的数字。rejoin replace/all parse str "<>," "91" "147"
将消除<>,
。我怎么能这样做?
答案 0 :(得分:3)
如果您的输入是:
st1: "...<id>90,123</id>...<id>190</id>...<id>123,90</id>...<id>123,90,123</id>...<id>901</id>"
然后试试这个:
delimiter: charset ">,<"
s: copy ""
rule: [
some [
copy del1 delimiter "90"
copy del2 delimiter (
append s rejoin [del1 "100" del2]
)
|
copy c skip (
print "other char" append s c
)
]
]
parse st1 rule
print s
将输出:
...<id>100,123</id>...<id>190</id>...<id>123,100</id>...<id>123,100,123</id>...<id>901</id>
这也帮我找到了一个红虫:)