htmlYou really hate Regular Expressions and discovered the power of Parse with our simple parse tutorials. Nevertheless after a while, you feel frustrated because even after reading the excellent manual, you’re still lacking some real world examples. So here’s an example for using none with Parse.

Let’s say you want to parse this:

content: {<tag attribute1="valueattribute1" attribute2="valueattribute2">
</tag>
<tag attribute2="valueattribute21" attribute1="valueattribute11" >
</tag>
}

or

content: {<tag attribute1="valueattribute1" attribute2="valueattribute2">
</tag>
<tag attribute2="valueattribute21">
</tag>
}

If you try this rule …

attribute1: [{attribute1="} copy valueattribute1 to {"} thru {"}]
attribute2: [{attribute2="} copy valueattribute2 to {"} thru {"}]

attributes-rule: [attribute1 attribute2 (print valueattribute1 print valueattribute2 )
| attribute2 attribute1(print valueattribute2 print valueattribute1)
]

rule: [any [to {<tag } thru {<tag } attributes-rule {>} to {</tag>} thru {</tag>}] to end]

… the second content won’t fully parse. Instead you have to add none keywords like this:


attribute1: [{attribute1="} copy valueattribute1 to {"} thru {"}]
attribute2: [{attribute2="} copy valueattribute2 to {"} thru {"}]

attributes-rule: [[attribute1 | none] [attribute2 | none] (print valueattribute1 print valueattribute2
valueattribute1: none valueattribute2: none)
| [attribute2 | none] [attribute1 | none] (print valueattribute2 print valueattribute1
valueattribute1: none valueattribute2: none
)
| none
]

rule: [any [to {<tag } thru {<tag } attributes-rule {>} to {</tag>} thru {</tag>}] to end]

If you test content 2 with last rule, you should get


>> parse content rule
valueattribute1
valueattribute2
none
valueattribute21
== true
>>

Bookmark and Share

Recent Articles