Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I saw your response soon after you posted it, but had to go to a meeting outside and did not have time. Coming back home, I tried a couple of things and it turns out to be more difficult than I thought.

Although this solution is far from elegant, it seems to work:

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.

In reply to Re^3: Regex Optional capture doesn't by Laurent_R
in thread Regex Optional capture doesn't by NetWallah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-19 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found