in reply to Re: Search patern within pattern in a single substitute command
in thread Search patern within pattern in a single substitute command

Looking back now, I knew nested pattern ((.).(..)) and should have thought about it here. It turned out to be the key. What does the \K mean? If I don't include it I get o/p
col2 cYl2 col3 col4 col5 5678 5Y78 9012 3456 7890
W/o \K the following works too, but I would like to understand \K
s[(.{5})((.).(..))(.*)][$1$2 $3Y$4$5], print while <DATA>;
This is something I would have written if I had thought about the nested pattern in the first place....

Replies are listed 'Best First'.
Re^3: Search patern within pattern in a single substitute command
by BrowserUk (Patriarch) on Mar 04, 2011 at 05:24 UTC
    What does the \K mean?

    from Perldoc perlre: "Character Classes and other Special Escapes"

    \K Keep the stuff left of the \K, don't include it in $&

    It says that the bit of the regex preceding it is only used to locate the part of the string to be replaced, but isn't a part of the substitution. It just saves the need for an extra capture.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Makes sense. Thanks a lot for your help.