Argh! This looked straightforward when first looked more than an hour ago. Now would appreciate wisdom from the Monastery (on which, details below). But before we get to that would also appreciate a little clarification from OP, EchoAngel:

Do you want the entire set of numeric values replaced with a single character string, "GOVALUE?"

And when you say "repeat my code" do you mean replicating it, in line, with essentially identical code?

In other words, please help me understand (I see there are others who may have provided the help you wanted) by an example or more precise description of the desired output (and the method of your "repeat my code."

Following comments reflect my (mis-)understanding, WHICH MAY BE WRONG -- corrections sought!

s/     start "substitution" -- not exactly "find and replace"
    abc    # match (but don't capture or keep) "abc"
    (\D+)    # capture one_or_more non-digits followed by a space
    ([\d\.\-]*)    # capture (as $2) zero_or_more digits, dots, slashes** or minus-signs (fol by a space)
    (.*)/    # On the data provided, capture (as $3) anything and everything except a newline, starting at the first comma after the first decimal value

** or are you trying to escape the hyphen in class? if so, that's not necessary as the first or last element because if its the last thing in a class it can't be a range operator

and replace the original $text with:
"values" followed by the non-digits in $1 "(open_paren, dquote)" followed by "GOVALUE" followed by the contents of $3 -- everything not previously captured in $1 or $2.

interpretation above developed from code; appears to match output
values(" GOVALUE, 0.074997, 0.103143, 0.153955, 0.260586", " 0.068394, 0.082183, 0.110329, 0.161142, 0.26777 +3", " 0.081887, 0.095677, 0.123822, 0.174635, 0.28126 +6", " 0.111534, 0.125324, 0.153470, 0.204282, 0.31091 +4", " 0.165731, 0.179521, 0.207666, 0.258479, 0.36511 +0")

...if your data is qq'ed into the value assigned to $text. ie,

#!c:/perl/bin -w $text = qq ( abc(" 0.123511, 0.074997, 0.103143, 0.153955, 0.26058 +6",\ " 0.068394, 0.082183, 0.110329, 0.161142, 0.2677 +73",\ " 0.081887, 0.095677, 0.123822, 0.174635, 0.2812 +66",\ " 0.111534, 0.125324, 0.153470, 0.204282, 0.3109 +14",\ " 0.165731, 0.179521, 0.207666, 0.258479, 0.3651 +10") ); $text =~ s/abc(\D+)([\d\.\-]*)(.*)/values$1GOVALUE$3/g; print "$text\n";

However, while trying to make certain I wasn't mistating (was I?) re escaping a initial or final hyphen in a class, I started playing with variant forms, such as:

$text2 = 'foo|abc-./|foo '; # $text2 =~ s%(foo|\w+)([//.-]+)(.*)%$1 :i: $2 :i: $3%g; # output is: ++foo|abc :i: -./ :i: |foo ++ # captures the hyphen, dot and slash in $2 with ONLY the fwd_slash esc +aped # and capturs "|foo " in $3 # $text2 =~ s%([\w|]+)([.-]+)(.*)%__$1_:_$2_:_$3__ : second variation% +g; # output is: ++__foo|abc_:_-._:_/|foo __ : second variation++ # hyphen, dot still captured in $2 with no escaping at all inside the +class $text2 =~ s%([\w|]+)([.-]+/)(.*)%$1:$2:$3 : third variation%g; # output is: ++foo|abc:-./:|foo : third variation++ # Moved the fw_slash (unescaped, using % as delimiters) into the secon +d capture # expression... and fw_slash turns up correctly in $2 print "\t++$text2++\n";

But the alternates above go all around the barn. Any hints, please, on a better way to do a demo on this (narrow) matter?


In reply to Re: Found a bug with Search and Replace command? by ww
in thread Found a bug with Search and Replace command? by EchoAngel

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.