2

There is a snippet from a XML file like this:

"...<id>90,123</id>...<id>190</id>...<id>123,90</id>...
<id>123,90,123</id>...<id>901</id>"

I want to replace all the number 90 with another number, e.g. 100. Using replace/all will ruin numbers like 190 and 901. rejoin replace/all parse str "<>," "91" "147" will eliminate the <>,. How can I do this?

Wayne Cui
  • 835
  • 7
  • 15

1 Answers1

3

If your input is:

st1: "...<id>90,123</id>...<id>190</id>...<id>123,90</id>...<id>123,90,123</id>...<id>901</id>"

Then try this:

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

Will output:

...<id>100,123</id>...<id>190</id>...<id>123,100</id>...<id>123,100,123</id>...<id>901</id>

This helped me find a Red bug as well :)

kealist
  • 1,669
  • 12
  • 26
  • Great! It solves my problem perfectly. Thanks a lot! Very happy to see that you found a Red bug by it. :) – Wayne Cui Dec 25 '13 at 14:43