Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
To explain further how your regular expression is problematic, in case you find it helpful:

What you're saying with "/(b)*?/" is that you want to match "b" and store it in $1, and do this zero or more times, but no more times than necessary. As ikegami notes, what you may mean is "/(b*?)/, which says that you want to match "b" zero or more times, but no more than necessary, and store the collection of characters matched in $1.

The difference is that the first might be trying to store any number of different single instances of "b" in $1, all of which are matched, it may even store no instances of "b" in $1. It may have trouble deciding which single instance to put in $1. It looks like back in 5.6.1 the regular expression engine gets really confused by this, as well it might.

In 5.8.x versions it looks like it decides to take the first instance, which is "no" occurances of "b".

Adendum for those who know the RE engine: I know this is not how the RE engine works on the string, it's meant as an explanation of why the expression is ambiguous, rather than how the RE engine works (which the general reader of an RE shouldn't have to know, IMO). The 5.6.1 engine has a bug here, but it is a lot to ask of the little engine that could.


In reply to Re: Strange result from "abbbbbc" =~ /(b)*?(b*?)c/ by rodion
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 musing on the Monastery: (2)
As of 2022-08-09 02:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?