Hi monks, I am trying to search and replace a desired portion from a line using perl but not able to match regex to the end of a word. let me explain the issue below

Line:

0 (0) tracegen chn:req cmd:SDP_CMD_RDSIZED unit:0x10 addr:0x0 len:0x3f + vc:0 qospri:0 qosfw:0 strm:0x0 chain:0 io:0

Code:

$line1 =~ s/addr\:0x.*\S/addr\:$address/;

Result:

0 (0) tracegen chn:req cmd:SDP_CMD_RDSIZED unit:0x10 addr:0x500000000

Unfortunately my code is trimming the rest of the line after addr field which shouldn't happen.

expected result:

0 (0) tracegen chn:req cmd:SDP_CMD_RDSIZED unit:0x10 addr:0x500000000 +len:0x3f vc:0 qospri:0 qosfw:0 strm:0x0 chain:0 io:0

Please suggest a solution to match next white space after addr field or to match end of string and replace. I've tried $, \s, \S, \z, \', etc. But doesn't worked well

2019-05-30 Athanasius added code tags


In reply to search and replace desired portion from a line by syedasadali95

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.