0

My String looks likes this

Dec 04 08:14:23 198.19.71.200 Dec 04 08:14:23 198.19.71.201

Where highligted string consist of two ip address

I am using below regex to capture ip's

(\d+.\d+.\d+.\d+)

Now i want to capture the last ip. How would i capture the last ip since my regex is capturing both the ip's ?

Any help will be appreciated. Thankyou

Kushal Kumar
  • 101
  • 1
  • 3
    Iterate through your captured groups and select the last one? – Kilazur Jan 22 '15 at 15:29
  • 2
    I don't know, what language/tool are you working with? I mean, you're not just using regular expressions out of the blue, are you? – Kilazur Jan 22 '15 at 15:49

1 Answers1

0

Use a negative look ahead:

((\d+\.){3}\d+)(?!.*(\d+\.){3}\d+)

See demo

Also slightly simplified the main regex and made it more specific to dots.

Bohemian
  • 365,064
  • 84
  • 522
  • 658