Are there regular expression equivalents for finding and modifying tree structures? Vibrant mini-languages (like perl regex) are what I'm looking for.
Here is an example that can clarify what I'm looking for.
<root> <node name="1"> subtrees .... </node> <node name="2"> <node name="2.1"> data </node> other subtrees... </node> </root>
The operation that would be possible on the aforementioned tree is “moving the subtree in node 2.1 to the subtree in node 1.” The result of the operation may look something like this.
<root> <node name="1"> subtrees .... <node name="2.1"> data </node> </node> <node name="2"> other subtrees... </node> </root>
Search and replace operations, such as searching for all nodes with 2 children, find all nodes whose data begin with “a” and replace them with “b” if the subtrees have at least 2 other brothers, etc., should be supported.
For strings where the only dimension is along the entire length of the string, we can perform many of the above operations (or their 1D equivalents) using regular expressions. I wonder if equivalents exist for trees. (instead of a single regular expression, you may need to write a set of conversion rules, but this is normal).
I would like to know if there is some simple mini-language (not a regular expression per.se, but something accessible, like regex through libraries, etc.). to perform these operations? Preferably, as a python library.
java c python regex
Jsn
source share