Where does the double backslash in \\K come from? Here is a complete working example:

#!/usr/bin/perl use strict; use warnings; sub processReplacements { my $regexM = shift @_; #TERM(S) TO MATCH my $regexR = shift @_; #REPLACEMENT TERM my $regexI = shift @_; #FLAG FOR CASE-INSENSITVE SUBSTITUTION my $sv = shift @_; # $sv => START, E.G. /^(.*)/; my $ev = shift @_; # $ev => END, E.G. /(.*)$/; my $ww = shift @_; # $ww => WHOLE-WORD, E.G. /\b(.*)\b/; my $ch = shift @_; # $ch => DELIMIT CHARS, # E.G. /[.,:;!?'"](.*)[.,:;!?'"]/; my @data = @_; # INCOMING ARRAY my @changed = (); # OUTGOING ARRAY my $line = ''; my $linehead = ''; my $sourceline = ''; my $m = $regexI ? qr{(?i:$regexM)} : qr($regexM); my $s = $sv ? qr(^) : qr(); my $e = $ev ? qr($) : qr(); my $b = $ww ? qr(\b) : qr(); my $c = $ch ? qr([.,:;!?'"]) : qr(); foreach my $line (@data) { push @changed, $line =~ s{$s$c$b\K$m(?=$b$c$e)}{$regexR}r; } return @changed; } foreach my $parm (qw(0:0:0:0:0 1:0:0:0:0 0:1:0:0:0 0:0:1:0:0 0:0:0:1:0 + 0:0:0:0:1)) { my @opts = split /:/, $parm; print "parm: $parm\n"; my @r = processReplacements('xxx', 'yyy', @opts, 'aaaxxxbbb', 'aaa xxx bbb', 'aaa:xxx:bbb', 'xxxbbb', 'aaa:XXX', 'a +aaxxx'); print "$_\n" foreach @r; print "\n"; }

which gives:

parm: 0:0:0:0:0 aaayyybbb aaa yyy bbb aaa:yyy:bbb yyybbb aaa:XXX aaayyy parm: 1:0:0:0:0 aaayyybbb aaa yyy bbb aaa:yyy:bbb yyybbb aaa:yyy aaayyy parm: 0:1:0:0:0 aaaxxxbbb aaa xxx bbb aaa:xxx:bbb yyybbb aaa:XXX aaaxxx parm: 0:0:1:0:0 aaaxxxbbb aaa xxx bbb aaa:xxx:bbb xxxbbb aaa:XXX aaayyy parm: 0:0:0:1:0 aaaxxxbbb aaa yyy bbb aaa:yyy:bbb xxxbbb aaa:XXX aaaxxx parm: 0:0:0:0:1 aaaxxxbbb aaa xxx bbb aaa:yyy:bbb xxxbbb aaa:XXX aaaxxx

-jo


In reply to Re^3: Executing CGI/web form directives in regex substitution without pages of code by jo37
in thread Executing CGI/web form directives in regex substitution without pages of code by Polyglot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.