in reply to How to start regexp from a X position

pos is not a read-only function, you can actually assign to it. However, that won't help you much, as you're matching <0>, and that only occurs once in the string.

As for you example, it can be written as:

$x =~ /(<0>)/$1<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:01 UTC

    Thank for your reply

    Yes, i matching <0> in the first example, but i can change it to <\d>, could be it help me with pos?

    i'm not put the question cleary, i was tried to replace in the last match, how could i do that?

    Thank again

      You can get the last match by adding .* in front of the regex.

      If you use perl 5.10.0 or newer, you can make use of the \K ("keep") assertion:

      use 5.010; my $str = '<1> <2> <3>'; $str =~ s/.*\K<\d>/<4>/; say $str; __END__ <1> <2> <4>

      If you want to add test after the match, you can use s/.*<\d>\K/ <4>/ instead.

        Ohh thank moritz, Perl is amazing, i'm using 5.10 so i'll read about the new feature \K and if i have a question I'll shoot!!!

        Thank a lot

      for ('<1>', '<2>', '<3>') { $x =~ /^(.*<\d>)/$1$_/s; }
      is just a complicated way of doing
      $x =~ /^(.*<\d>)/$1<1><2><3>/s;

        Yes Ikegami you right, i really try to understand how the pos function works and c and \G modifiers, as say the perlmonk's rule i put a simple example to try to demostrate what's I want to do

        thank I very appreciate the effort you people