DB<1> $x = q|<blah1 phase="2" type="MyType" more_keys="Values" <Unwa
+nted/> <SomeTagIwant><k1="v1"></SomeTagIwant>|;
DB<2> $y = q|<blah1 phase="2" type="MyType" more_keys="Values" <Unwa
+nted/> <SomeTagIDontWant><k1="v1"></SomeTagIDontWant>|;
DB<3> print "$_ " for $x =~ /type="([^"]+)".+?(\w+?TagIwant) | typ
+e="([^"]+)"/x;
MyType SomeTagIwant
DB<4> print "$_ " for $y =~ /type="([^"]+)".+?(\\w+?TagIwant) | ty
+pe="([^"]+)"/x;;
MyType
DB<5>
It could be slightly improved with a named regex:
DB<6> $type = qr/type="([^"]+)"/;
DB<7> print "$_ " for $x =~ /$type .+?(\w+?TagIwant) | $type /x;
MyType SomeTagIwant
DB<8> print "$_ " for $y =~ /$type .+?(\w+?TagIwant) | $type /x;
MyType
Well, I think that haukex's solution below looks better.
|