Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

First, I'm not the right person to be asking this question of. Whatever regex expertise I once had is well out of date. There is a whole bunch of stuff I've never done anyting with. However, this is my interpretation of the decidedly unclear documentation:

Three matches?

The (what appears to be called) zero-length switch assertion, appears to succeed, whenever the condition part succeeds; regardless of whether the yes pattern (or no pattern, if present) succeed.

So with 6 characters in your string, and a condition that restricts matching to every second character, the overall match succeeds 3 times, even if the yes pattern only matches at 2 of those positions. Hence your output.

Also, I notice the x modifier doesn't work with a conditional pattern:

It appears that you are breaking up an indivisible token with the whitespace you've used. This works:

C:\test>perl -M5.010 -w my $str = 'bxAybz'; while ( $str =~ / (?(?{1}) (b[xyz]) ) /gx ) { say 'yes'; say $1; } ^Z yes bx yes bz

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^2: A regex that only matches at offset that are multiples of a given N? by BrowserUk
in thread A regex that only matches at offset that are multiples of a given N? by BrowserUk

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 taking refuge in the Monastery: (5)
As of 2024-04-24 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found