Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

If indeed that is what you get then there is a bug (what version of Perl?). If I run:

"abbbbbc" =~ /(b)*?(b*?)c/; print "($1)($2)\n";

it prints:

()(bbbbb)

as expected. However the following may provide a little illumination:

"abbbbbc" =~ /(b)*?(b*?)c/; print "\$1: $1\n" if defined $1; print "\$2: $2\n" if defined $2; Prints: $2: bbbbb

Note no $1 printed - it's undefined because the minimum number of times it could match is 0. Perhaps you need to tell us something about the bigger picture. It looks like you are asking for the answer to the wrong question.

Update: "as expected" because (b*?) doesn't backtrack. It matches the first b found and the minimum number more that it can and still make a match. Consider:

"babbbbbcbbbcx" =~ /(b*?)/; print ">$1<\n"; # '><' - matched none "babbbbbcbbbcx" =~ /(b*?)c/; print ">$1<\n"; # '>bbbbb<' - matched b following a through b preceedi +ng c

DWIM is Perl's answer to Gödel

In reply to Re: Strange result from "abbbbbc" =~ /(b)*?(b*?)c/ by GrandFather
in thread Strange result from "abbbbbc" =~ /(b)*?(b*?)c/ by mcovic

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 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? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-08-07 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?