Question

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?

Was it helpful?

Solution

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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top