Regex for xml parsing
- by ogmios
What is your opinon about following regexes - is it correct?
To find element with spcific and required attribute
"<(" + elem_name +
")(\s+(?:[^<]?\s+)" + attr_name +
"\s*=\s*(['\"])((?:(?!\3).))\3[^<])(.*?)"
To find element with spcific but optional attribute
"<(" + elem_name +
")(\s*|\s+(?:[^<]?\s+)(?:" +
attr_name +
"\s*=\s*(['\"])((?:(?!\3).))\3)?[^<])(.*?)"
Pleas not another answer "use existing xml parser". Question is - are the regexes proper or not? This is specific situation - C language in embedded system and xml is not well-formed (cannot be fixed - does not depend on me). Xml have specified schema and no problem with namespaces etc. exists.