in reply to Re: How to start regexp from a X position
in thread How to start regexp from a X position

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

  • Comment on Re^2: How to start regexp from a X position

Replies are listed 'Best First'.
Re^3: How to start regexp from a X position (5.10 regex feature)
by moritz (Cardinal) on Oct 07, 2008 at 12:15 UTC
    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

Re^3: How to start regexp from a X position
by ikegami (Patriarch) on Oct 07, 2008 at 12:08 UTC
    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

        See the bottom bit of "What good is \G in a regular expression?" in perlfaq6 for a useful purpose for /c. Probably the only useful purpose for it :)