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

Re^3: Regular expressions: interpolate the variable in the value of the number of repetitions for the group

by rjt (Deacon)
on Aug 03, 2013 at 10:29 UTC ( #1047690=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regular expressions: interpolate the variable in the value of the number of repetitions for the group
in thread Regular expressions: interpolate the variable in the value of the number of repetitions for the group

Heh... Thanks, but I want to do it the forces of the regular expression (without external code).

The really funny thing is, all of the broken examples you cite as somehow desirable in the root node execute "external code" (which I take to mean non-regex Perl code), via the experimental features (?{ ... }) and (??{ ... }):

0day's code:

$binary_data =~ /(.)(.){(?{unpack 'H*', $1})}/; # ? /(.)(?{unpack 'H*', $1})(.){$^R}/; # ??? /(.)((??{'.' x $1}))/; /(\d)((??{'.*?\n' x $1}))/;

how to assign a value aaaa\n of $3, bbbb\n -> $4 etc ?

Short answer: you can't, unless you're OK with this:

/(\d) ([^\d]+?\n)? ([^\d]+?\n)? ([^\d]+?\n)? ([^\d]+?\n)? ([^\d]+?\n)? ([^\d]+?\n)? ([^\d]+?\n)? ([^\d]+?\n)? ([^\d]+?\n)? /x; printf "%d: <%s>\n", $_, eval '$'.$_ for 2..$1+1;

But, no doubt you already thought of that. I want to help you, and to do that, I need a complete description of the actual problem you're trying to solve that you need our help with, as well as some real examples of input and expected output.

  • Comment on Re^3: Regular expressions: interpolate the variable in the value of the number of repetitions for the group
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047690]
help
Chatterbox?
[Corion]: ambrus: Oh - that one would be much harder to automate... The SYNOPSIS section should mostly be a runnable program IMO, but I write only small snippets in my documentation for single functions/methods, and creating the appropriate environment for ...
[Corion]: ... those in an automated fashion seems somewhat hard to me. Although it should do wonders for the test coverage ;)
[haukex]: Corion: I once wrote an automated thingy for that here
[haukex]: here's the code that uses it
[Corion]: haukex: Hmm - maybe I can reuse that. I see that it uses Pod::Parser, which I think was one of the more fragile parsers. But if I'm statically (re)generating the tests instead of doing that "live" on the client/tester machines, that's a much smaller...
[Corion]: ... problem space than trying to cater to all versions of Pod::Parser(s)
[haukex]: I think you're right, I think Pod::Simple is the preferred parser now

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-02-27 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.