Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting regex matches in Scala?

Tags:

regex

scala

In Scala I am trying to detemine the number of types a particular match is found (and it can occur several times in the same string). Namely, something that is of form "##/nnn-#" where # is a number 0-9 and n is a letter A-Za-z and - is a hiphen and / is a forward slash.

like image 907
user51819 Avatar asked Jun 26 '15 03:06

user51819


1 Answers

You mean something like this?

scala> val reg = "[0-9]{2}/[a-zA-Z]{3}-[0-9]".r
scala> val str = "12/abc-2 abcd 55/bar-2 foo bar"
scala> reg.findAllIn(str).length
like image 118
hwnd Avatar answered Oct 20 '22 20:10

hwnd