One mistake I see people making over and over again is trying to parse XML or HTML with a regex. Here are a few of the reasons parsing XML and HTML is hard:
People want to treat a file as a sequence of lines, but this is valid:
attr="5"
/>
People want to treat < or People often want to match starting tags to ending tags, but XML and HTML allow tags to contain themselves (which traditional regexes cannot handle at all): People often want to match against the content of a document (such as the famous "find all phone numbers on a given page" problem), but the data may be marked up (even if it appears to be normal when viewed): Comments may contain poorly formatted or incomplete tags: What other gotchas are you aware of?foo
(703)
348-3020foo
bar
No comments:
Post a Comment