Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

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

As given, your example does not match anything. If you use re 'debug'; you will get a fairly cryptic trace of what the regular expression is doing:

$ perl -Mre=debug -E 'my @m='lkjkljkjlkhkjkfjkfkvklkv'=~/^\w*(kl(?1)\w*).*?(kv)/g; say for @m;'
Compiling REx "^\w*(kl(?1)\w*).*?(kv)"
Final program:
   1: SBOL /^/ (2)
   2: STAR (4)
   3:   POSIXU\w (0)
   4: OPEN1 (6)
   6:   EXACT <kl> (8)
   8:   GOSUB1-4:4 (11)
  11:   STAR (13)
  12:     POSIXU\w (0)
  13: CLOSE1 (15)
  15: MINMOD (16)
  16: STAR (18)
  17:   REG_ANY (0)
  18: OPEN2 (20)
  20:   EXACT <kv> (22)
  22: CLOSE2 (24)
  24: END (0)
floating "klkl" at 0..9223372036854775807 (checking floating) anchored(SBOL) minlen 6 
Matching REx "^\w*(kl(?1)\w*).*?(kv)" against "lkjkljkjlkhkjkfjkfkvklkv"
Intuit: trying to determine minimum start position...
  doing 'check' fbm scan, 0..22 gave -1
  Did not find floating substr "klkl"...
Match rejected by optimizer
Freeing REx: "^\w*(kl(?1)\w*).*?(kv)"

The trace says your match never got started because the string being matched does not contain 'klkl'. The first 'kl' is the literal one from your regular expression; the second is because of the recursion. I believe that even if the string contained 'klkl' there would be no match, because there is no way for the recursion to end; it would just look for 'klklkl', then 'klklklkl', and so on.

Can you say what you expect @m to contain in your example?

And can you provide an example where you match against the shortest possible string that you want to match successfully?


In reply to Re: To not capture recursive group while collecting certain matches by Anonymous Monk
in thread To not capture recursive group while collecting certain matches by Anonymous Monk

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 sharing their wisdom with the Monastery: (9)
As of 2024-04-18 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found