yoda54 has asked for the wisdom of the Perl Monks concerning the following question:
Monks,
I am a bit confused with multi line matching, how can I get the value of property name "Text" to match since it spans across multiple lines?
Thanks!
#!/usr/bin/perl use strict; use warnings; while(<DATA>) { if (/<cdset id/.../<\/cdset/) { if ($_ =~ /<property name="(.*)"\s+value="(.*)"\/\>/ms) { print "$1 -> $2\n"; } elsif ($_ =~ m/<property name="(.+)"\s+value=""\/\>/) { # if no value print "$1 -> \"\"\n"; } } } __DATA__ <?xml version="1.0" encoding="utf-8" standalone="yes"?> <set name="01" id="test" catId="81679" > <cdsets> <cdset id="cdset" name="CD Compilation"> <property name="Own" value=""/> <property name="Type" value="Record"/> <property name="Text" value="Sample text more sample text more more same text]."/> <property name="Unique" value="yes"/> </cdset> </cdsets> </set> Output: Own -> Type -> Record Unique -> yes
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Regex Multiline Matching (XML::Twig)
by beech (Parson) on Oct 14, 2016 at 00:18 UTC | |
by yoda54 (Monk) on Oct 14, 2016 at 01:34 UTC | |
|
Re: Perl Regex Multiline Matching
by choroba (Cardinal) on Oct 14, 2016 at 05:38 UTC | |
|
Re: Perl Regex Multiline Matching
by morgon (Priest) on Oct 14, 2016 at 00:13 UTC | |
|
Re: Perl Regex Multiline Matching
by kcott (Archbishop) on Oct 14, 2016 at 09:21 UTC | |
|
Re: Perl Regex Multiline Matching
by BrowserUk (Patriarch) on Oct 14, 2016 at 00:13 UTC | |
by yoda54 (Monk) on Oct 14, 2016 at 00:35 UTC |