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:


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.


see demo


Related Query

More Query from same tag