score:0

Accepted answer

Here's a rather nasty regex that deals with it: (\d{1,3}(?:\.\d{1,3}){3})\s+(\d{1,3}(?:\.\d{1,3}){3})\s+(private|public)

Using kantan.regex, you can express the whole thing as follows:

import kantan.regex.implicits._

// Where `input` is your string.
input.unsafeEvalRegex[(String, String, String)](rx"(\d{1,3}(?:\.\d{1,3}){3})\s+(\d{1,3}(?:\.\d{1,3}){3})\s+(private|public)")

This yields an Iterator[(String, String, String)] that, when ran through foreach(println _), results in:

(192.10.678.234,192.12.898.123,public)
(192.10.567.6,3.3.3.3,public)
(192.20.123.39,123.34.31.678,private)

If you're interested in better types (say, an Entry class for each entry, representing each IP address in a dedicated type and having public and private as an ADT), let me know and I can amend the code to deal with that as well - the whole point of kantan.regex is to extract well typed data from strings through regular expressions.

score:0

see demo

(?:(?:\d{1,3}\.){3}\d{1,3}\s*){2}([a-z]+)


Related Query

More Query from same tag