def root(self, names=None, wildcard=None, regex=None):
<EOL>nself = self.copy()<EOL>try:<EOL><INDENT>node = fuzzy_match_tipnames(<EOL>nself, names, wildcard, regex, True, True)       <EOL><DEDENT>except ToytreeError:           <EOL><INDENT>tipnames = fuzzy_match_tipnames(<EOL>nself, names, wildcard, regex, False, False)<EOL>tipnames = list(set(self.get_tip_labels()) - set(node))<EOL>node = fuzzy_match_tipnames(<EOL>nself, tipnames, None, None, True, True)<EOL><DEDENT>if not nself.is_bifurcating():<EOL><INDENT>nself.treenode.resolve_polytomy()<EOL><DEDENT>nself.treenode.set_outgroup(node)<EOL>nself._coords.update()<EOL>testnode = nself.treenode.get_leaves()[<NUM_LIT:0>]<EOL>features = {"<STR_LIT:name>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"}<EOL>extrafeat = {i for i in testnode.features if i not in features}<EOL>features.update(extrafeat)<EOL>nnode = [i for i in nself.treenode.traverse() if not hasattr(i, "<STR_LIT>")]<EOL>if nnode:<EOL><INDENT>nnode = nnode[<NUM_LIT:0>]<EOL>rnode = [i for i in nself.treenode.children if i != node][<NUM_LIT:0>]<EOL>idxs = [int(i.idx) for i in nself.treenode.traverse()<EOL>if hasattr(i, "<STR_LIT>")]<EOL>if len(node.is_leaf()) == <NUM_LIT:1>:<EOL><INDENT>nnode.name = str("<STR_LIT>")<EOL>rnode.name = node<EOL>rnode.add_feature("<STR_LIT>", max(idxs) + <NUM_LIT:1>)<EOL>rnode.dist *= <NUM_LIT:2><EOL>sister = rnode.get_sisters()[<NUM_LIT:0>]<EOL>sister.dist *= <NUM_LIT:2><EOL>rnode.support = <NUM_LIT:100><EOL>for feature in extrafeat:<EOL><INDENT>nnode.add_feature(feature, getattr(rnode, feature))<EOL>rnode.del_feature(feature)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>nnode.add_feature("<STR_LIT>", max(idxs) + <NUM_LIT:1>)<EOL>nnode.name = str("<STR_LIT>")<EOL>nnode.dist *= <NUM_LIT:2><EOL>sister = nnode.get_sisters()[<NUM_LIT:0>]<EOL>sister.dist *= <NUM_LIT:2><EOL>nnode.support = <NUM_LIT:100><EOL><DEDENT><DEDENT>nself.treenode.ladderize()<EOL>nself._coords.update()<EOL>return nself<EOL>
(Re-)root a tree by creating selecting a existing split in the tree,
or creating a new node to split an edge in the tree. Rooting location
is selected by entering the tips descendant from one child of the root
split (e.g., names='a' or names=['a', 'b']). You can alternatively
select a list of tip names using a fuzzy selector based on a unique
shared string (wildcard="prz") or a regex matching pattern.

Example:
To root on a clade that includes the samples "1-A" and "1-B" you can
do any of the following:

rtre = tre.root(outgroup=["1-A", "1-B"])
rtre = tre.root(wildcard="1-")
rtre = tre.root(regex="1-[A,B]")