简体   繁体   中英

regex with XML tags

I currently work on an XML parser, and I need to use regex to get all my tags to put them in a tree.

My file looks like

<block1>
   <tag1>
       <subtag1>a</subtag1>
       <subtag2>b</subtag2>
   </tag1>
   <tag2>
       <subtag3>c</subtag3>
       <subtag4>d</subtag4>
   </tag2>
</block1>

I would like my regex to match with

<block1>
<tag1>
<subtag1>
<subtag2>
<tag2>
<subtag3>
<subtag4>

To avoid getting the end tags I escaped the "/" and it works quite well.

My last problem is that I get the whole single-line tags because the first "<" goes with the last ">"...

I am using

boost::regex r("(<[^/].*>)");

Thanks in advance,
dubill_a

/(<\w+>).*?/

演示/说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM