you can define a recursive regex rule
regex element { '<' (<[\w\-]>+) '>' # Opening tag [ <-[<>]>+ | ~ ]* # Use tilde for recursion '</' $0 '>' # Closing tag }
or you could go with a Grammar
grammar MiniXML { token TOP { ^ <element> $ } rule element { '<' <tag> '>' <content>* '</' $<tag> '>' } token tag { \w+ } token content { <-[<>]>+ } }
you can define a recursive regex rule
https://docs.raku.org/language/regexes#Tilde_for_nesting_str...or you could go with a Grammar
(or just use a library module like XML::Class or XML::Tiny)