in reply to Regular expression to check XML type
Even for something as seemingly simple as that, you should still reach for a parser. You can certainly make do with regular expressions but a parser buys you much more, will fall down less, is easier to write and read, and won't give you false positives. Your sample XML, for example, is broken but your regex wouldn't tell you that.
use strict; use warnings; use XML::LibXML; my $doc = XML::LibXML->new->parse_fh(\*DATA); print "All about me-\n", " Version: ", $doc->version, "\n", " Encoding: ", $doc->encoding, "\n", " Standalone: ", $doc->standalone, "\n"; __DATA__ <?xml version="1.0" encoding="UTF-8"?><sample></sample>
All about me- Version: 1.0 Encoding: UTF-8 Standalone: -2
|
|---|