in reply to How to start regexp from a X position

Here a way of doing it with pos:
my $x = "<0>"; my $pos = 0; for (qw {<1> <2> <3>}) { pos($x) = $pos; $x =~ s/\G(<\d+>)/$1$_/; $pos += length $1; } say $x; __END__ <0><1><2><3>

Replies are listed 'Best First'.
Re^2: How to start regexp from a X position
by pkt (Initiate) on Oct 07, 2008 at 12:20 UTC

    Thank!! great!!!, you open my mind, really i was knew that the solution is around that but i couldn't understand the documentation, perfect!!!!.

    One last question, how works the modifier c and \G in a regexp

    Could i do something like this:

    my $x = "<0>"; for (qw {<1> <2> <3>}) { if ($x =~ /<\d+>/gc) { $x =~ s/\G(<\d+>)/$1$_/; } } say $x;

    Really thank JavaFan

      Thank!! great!!!, you open my mind,

      You picked the worst of the presented solutions solely because it used pos as you initially believed it should. That's the very definition of a closed mind.

        Don't angry with me!!!, yes you right i'm a little closed mind, and you and JavaFan help me open it, when you said use .* i said me couldn't be more stupid it's right!!!, i really fight before posting here for many hours and i cuoldn't find a solution, becouse of that i reasearch about not common at least for me functio, variable and operators like pos, $&, \G, etc, etc, but finally you right :-)

        Thank to both

      I've no idea how to incorporate the /c modifier. It'll be pointless for two reasons. First, one sets pos() before matching, so who cares about the effect of /c. Second, /c would only kick in if you add a substring foo to $x, and the next time around, foo isn't there.

        Ok, JavaFan