Scala regex match failing with scala.MatchError for \w and \d (word or digit) match -


i trying basic regex pattern matching. although syntax seems correct, it's failing when use \w or \d word , digit matching.

import scala.util.matching.regex  object ex {   def main(args:array[string]):unit = {     val pattern =  new regex("(\\w)\\s(\\d)");     val pattern(words,num) = "asas1 11"     print(words+" "+num)   } } 

this error get:

exception in thread "main" scala.matcherror: asas1 11 (of class java.lang.string)     @ com.cccu.semantic.ex$.main(ex.scala:8)     @ com.cccu.semantic.ex.main(ex.scala) 

note: using scala ide build of eclipse sdk, build id 4.4.1 scala 2.11.8 on windows machine.

\w , \d match single character, need add there + modifier. throwing exception because can't match input against regular expression.

scala> val pattern =  new regex("(\\w+)\\s(\\d+)");    val pattern(words,num) = "asas1 11" pattern: scala.util.matching.regex = (\w+)\s(\d+) words: string = asas1 num: string = 11 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -