Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Regex to match an IP address that is embedded inside of another string

by GrandFather (Saint)
on Apr 19, 2016 at 22:05 UTC ( [id://1160940]=note: print w/replies, xml ) Need Help??


in reply to Regex to match an IP address that is embedded inside of another string

Take a look at Regular expression anchors. In particular \b.

Premature optimization is the root of all job security
  • Comment on Re: Regex to match an IP address that is embedded inside of another string

Replies are listed 'Best First'.
Re^2: Regex to match an IP address that is embedded inside of another string
by adamZ88 (Beadle) on Apr 19, 2016 at 22:13 UTC

    Thank you for your prompt response. The colon and other hex characters will always follow the last octet. I Tried your suggestion, and it still matches other ips that begin the same way on the fourth octet. Here is how I modified my code

    if ($linebuf =~ /\d+\.$oc1\.$oc2\.$oc3\.$oc4:*/

      As I stated in my above post, you need to get rid of the *.

        Thank you, that did it. I also had to add "^" at the beginning of my RegEx<\p>

Re^2: Regex to match an IP address that is embedded inside of another string
by adamZ88 (Beadle) on Apr 19, 2016 at 22:26 UTC

    Will do, Thank you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1160940]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-16 16:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found