ׁHi Honza,

On Thu, 25 Aug 2011 10:42:20 +0200
Honza Mach <jan.m...@cesnet.cz> wrote:

> Hi everybody,
> 
> I was wondering, if it is possible to use backreferences in the pattern
> repetition bracket operator.
> 
> Consider the following string:
> 
> my $string = "5 abcdefghijklmn";
> 
> The number five at the beginning of the string means, that I want to
> extract first five characters from the latter part of the string. I
> tried the following code, but it doesn`t work:
> 
> $string =~ s/(\d+)\s+(.{\g1})//;
> print "extracted: $1 $2\n";
> 
> The desired output would be:
> 
> extracted: 5 abcde
> 
> It seems, that it is not possible to use backreferences within the
> bracket operator (or am I doing something wrong?).
> 

I don't think it's possible, because the perl regex engine is not that smart.

> Is there other solution to my problem.
> 

You can use incremental parsing using \G and /g. See:

http://perl-begin.org/uses/text-parsing/

Regards,

        Shlomi Fish


-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Knuth is not God! Typing “God” into Google and pressing “I’m Feeling Lucky”
will not lead you to his homepage.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to