tags:

views:

462

answers:

2

What I need is something like this:

/<[\w\d]+ ([\w\d]+\=[w\d])+\/>/

Something that would match several attribute key/value pairs. Is that possible?

+10  A: 

You'll have much more succes using an XML parser, for example, XML::Parser. Parsing XML using regular expressions is very difficult (impossible?) and unless your use case is trivial, a proper XML parser is the reliable solution.

Brian Agnew
Impossible without a question mark. XML is not a regular language. Of course, some implementations of 'regular expressions' actually match non-regular languages, but that's another matter.
High Performance Mark
+6  A: 

It may be possible for a very limited range of valid XML. If you are trying to parse XML, I strongly recommend that you use a parser, rather than try to use regular expressions. XML::Twig is a good general-purpose parser available from CPAN.

For further reading, see also: XML parsing vs Regular expressions

toolic