0

I'm trying to write a script in Ruby that extracts some IP and different informations from a NMAP scan output. I'm using regular expressions and I already know how to properly extract IPs but there's something I'm not fully understanding with the grouping concept.

Let's say I have the current string in the file and I want to extract the IP value:

"Nmap scan report for 10.50.96.1"

Here I'm playing around with pry and building my script to recognize IP:

>> string = "Nmap scan report for 10.50.96.1"
=> "Nmap scan report for 10.50.96.1"
>> test = /(\d{1,3}\.){3}/.match(string)
=> #<MatchData "10.50.96." 1:"96.">

I do not understand why the global variable $1 is set as 96..

Shouldn't I have 3 groups, with the 3 values 10., 50. and 96.?

Mr.Laf
  • 17
  • 6

0 Answers0