score:0
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
(?:(?:\d{1,3}\.){3}\d{1,3}\s*){2}([a-z]+)
Source: stackoverflow.com
Related Query
- Working regex fails when using Scala pattern matching
- Scala Regex pattern matching issue when using |
- Pattern matching using regex with Scala Anorm
- Pattern matching using regex in Scala
- Scala Get First and Last elements of List using Pattern Matching
- Using regex in Scala to group and pattern match
- What is the advantage of using scala pattern matching instead of java switch case?
- scala - using filter with pattern matching
- Regex and Pattern Matching in Scala Part II
- Scala array pattern matching using regular expressions
- Why is pattern matching ok in scala but using instanceof is a sign of bad code in Java
- Regex Pattern Within Case Class Pattern Using Scala
- Pattern Matching with Multiple Regex in Scala
- Pattern Matching Scala Regex evaluation
- Using pattern matching with Specs2 and Play in Scala
- Using pattern matching for Ordered.compare in Scala
- How to arrange return order in an idiomatic way using pattern matching in Scala
- Using Scala pattern matching to extract XML elements with a certain name, regardless of content
- Deprecated - Scala Regex Pattern Matching
- Complex pattern matching on templace using Scala Play
- Extract the repetitive parts of a String by Regex pattern matching in Scala
- Regex Matching using Matcher and Pattern
- How to do regex pattern matching in Scala
- Scala regex pattern match groups different from that using findAllIn
- scala code for regex pattern matching
- Swapping values in an array using Pattern Matching in Scala
- Why does Regex pattern matching not work sometimes in Scala
- Pattern Matching Case Match using Scala
- How to replace part of string using regex pattern matching in scala?
- Scala sum of all elements in the leaves of a tree using pattern matching
More Query from same tag
- Scala 2D array sorting by primary and secondary colums
- spark: convert dataframe to svm labeled point
- How to create a nested generated column (as part of StructType) in a delta table?
- Calculate the time difference
- Adding inline images to Mailgun emails using Scala and Play WS
- Scala Real Interval, Int Interval
- Getting undefined type of value in a Spark Dataframe
- ScalaMock and the Cake Pattern - Why is my stub not called?
- Intellij: "Error running Scala Console: Cannot Start Process"
- Extract label values from a LabelledGeneric instance
- Implementing a real "forall" on a list of scala futures
- Scala for loop on Seq of objects within Object
- Scala this.type conformance to type parameter bounds of supertype
- Blocking calls in Akka Actors
- how to serve dynamic content in playframework 2
- For loop inside a .map() in scala: return type is "Unit"
- How to run scala repl with java 11?
- What is the preferred way in mill to point to the directory where build.sc file is located?
- A good place to define your case classes?
- Using functions as applicative functors/cartesians
- [json4s]:Extracting Array of different objects
- Scala Implicit convertions: 2 way to invoke
- unicast in Play framework and SSE (scala): how do i know which stream to send to?
- ReactiveMongo aggregate count function
- Create control constructs without funny restrictions on line breaks in Scala DSL
- Scala: List[Tuple3] to Map[String,String]
- Cassandra Spark Connector - NoSuchMethodError: scala.runtime.ObjectRef.zero()Lscala/runtime/ObjectRef
- Get sequence of types from HList in macro
- Flink 1.3.1, Elasticsearch 2.4.6, RuntimeException: Elasticsearch client is not connected to any Elasticsearch nodes
- PlayRunHook does not work in multi module projects