Created
February 13, 2020 09:23
-
-
Save saswata-dutta/ed5ab26bee7b3a3dfc264ef18440b41f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val PATTERN = """\s*SELECT\s+(.+?)\s+FROM\s+(.+?)(\s+WHERE\s+(.+?))?\s*""".r | |
PATTERN: scala.util.matching.Regex = \s*SELECT\s+(.+?)\s+FROM\s+(.+?)(\s+WHERE\s+(.+?))?\s* | |
scala> "SELECT a,b FROM t WHERE c=1,d=2" match {case PATTERN(f, t, _, c) => println(s"|$f|$t|$c|")} | |
|a,b|t|c=1,d=2| | |
scala> " SELECT a,b FROM t " match {case PATTERN(f, t, _, c) => println(s"|$f|$t|$c|")} | |
|a,b|t|null| |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment