Regex to catch only one occurrence of the right equerda

Asked

Viewed 44 times

-4

I’m looking for a Regex to pick up only the right IP address. I’ve tried some things but I can’t find out, that was the regex that seemed to work out best /((?[0-9]{1,3}\.){3}[0-9]{1,3})\s/g but she doesn’t take the IP’s that are in parentheses, I believe it is not the best way to assemble the expression. PS: I left in bold the values I want to take with regex.

Nmap scan report for whm.ixcsoft.com.br (45.174.128.220)
Host is up (0.047s Latency).
Nmap scan report for 231.128.174.45.ixcsoft.com.br (45.174.128.231)
Host is up (0.048s Latency).
Nmap scan report for 192.168.25.2
Host is up (0.048s Latency).
Nmap scan report for 192.168.25.3
Host is up (0.048s Latency).

  • Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativities worth reading the Stack Overflow Survival Guide in English.

1 answer

1


Simply remove the \s and redundant parentheses, unless their regular expression is a capture in a larger: (?:[0-9]{1,3}\.){3}[0-9]{1,3}(?=\s|\)|$).

Also add an advance statement (?=\s|\)|$) to ensure that the IP address is followed by a blank space, closing parentheses or new line.

https://regex101.com/r/pYwRXy/2.

Sorry if my Portuguese is imperfect.

  • So he takes more than one match per line, ie if I run without will catch the two IP’s of the line when I want to catch only the last one. Nmap scan report for 231.128.174.45.ixcsoft.com.br (45.174.128.231)

  • @Krisque, see the updated response.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.