The requirement is not entirely clear (and there is a contradiction between your description of the need and the code you show), but a simple correction to your Perl one-liner could be something like this:
perl -pi.bak -e 's/ip-compute-[\d.]{7,15}-internal/ip-compute-10.25.25 +.25-internal/g' test.txt
Since I am not sure of what you need exactly, this is an example of running this command showing what it does:
$ cat test.txt text.txt yoda yoda yoda ip-compute-10.10.10.1-internal yadda yadda yadda some more stuff $ perl -pi.bak -e 's/ip-compute-[\d.]{7,15}-internal/ip-compute-10.25. +25.25-internal/g' test.txt $ cat test.txt text.txt yoda yoda yoda ip-compute-10.25.25.25-internal yadda yadda yadda some more stuff
Please note that this is a very very naive approach to IP address matching and that the [\d.]{7,15} pattern is only looking for any combination of 7 to 15 digits and dots. It might match many things other than IP addresses, such as a phone number (read carefully davido's caveats on the subject in his post above). In this specific case, however, one might argue that it is relatively safe to use this because the words "ip-compute-" and "-internal" coming respectively immediately before and after the numbers-and-dots matching part are making false matching relatively unlikely, but you are the only one to know the real content of the file you want to process and you are therefore the only one to be able to know whether this will be sufficient. If you need the match to be more selective, then you run into exactly the kind of problem that davido is describing: we probably don't want to reinvent the wheel.

In reply to Re: Newbie regular expressions question by Laurent_R
in thread Newbie regular expressions question by bayareamonk

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.