perl - replace string

Discussion in 'Programming' started by pgiddy, Aug 21, 2008.

  1. #1
    I have the following string:

    Received: from mail.server.com (unknown [75.101.111.111])
    Code (markup):
    and I find the IP address 75.101.111.111 using this regex:

    $sendingip =~ m/\[.*?((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![\d])\]/is;
    Code (markup):

    How can I replace 75.101.111.111 with 127.0.0.1 and change the string to this:

    Received: from mail.server.com (unknown [127.0.0.1])
    Code (markup):

    Thank you, Perl wizards!

    ~pgiddy
     
    pgiddy, Aug 21, 2008 IP
  2. pgiddy

    pgiddy Peon

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    found the answer using s///

    $string=~s/\[.*?((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![\d])\]/127.0.0.1/;
    Code (markup):
     
    pgiddy, Aug 21, 2008 IP