go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Your solution does not work. Initially, it will appear to work against his data set, but XML start and end tags don't have to appear on the same line. If that happens, your regex will break because the dot metacharacter doens't match the newline. Adding the /s modifier allows the dot to match, but then, because your match is greedy, it still breaks:
See Death to Dot Star! for the explanation of why your regex fails (and for some excellent examples of how I have screwed up regexes on delimited text). Use a parser for data like this. Regexes, while I love them, are for matching data, not parsing it. As for your 'related note', it doesn't work because you have (.?) in your code. The dot/question mark makes you match one character and have that match optional. It's equivalent to (.{0,1}).
Cheers, Join the Perlmonks Setiathome Group or just click on the the link and check out our stats. In reply to (Ovid - don't use regexes for parsing) Re(2): Parsing XML
by Ovid
|
|