Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

in https://raku.org,

you can define a recursive regex rule

  regex element {
    '<' (<[\w\-]>+) '>'     # Opening tag
        [ <-[<>]>+ | ~ ]*   # Use tilde for recursion
    '</' $0 '>'             # Closing tag
  }
https://docs.raku.org/language/regexes#Tilde_for_nesting_str...

or you could go with a Grammar

  grammar MiniXML {
    token TOP { ^ <element> $ }
    rule element { '<' <tag> '>' <content>* '</' $<tag> '>' }
    token tag { \w+ }
    token content { <-[<>]>+ }
  }
(or just use a library module like XML::Class or XML::Tiny)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: