8
In Ruby, if I have two Regexps, I have the possibility to create another regexp like this:
a = /\d+/ # Matches digits
b = /\s+/ # Matches whitespaces
c = Regexp.union(a, b) # Matches sequences that consist only of digits or only of whitespaces
I want to do the same thing in Scala, but I didn't find out how I could do that. Note that I am not asking for a syntax to create a union of character classes like (\d+)|(\s+) in the previous example, I am really looking for a possibility to create a new Regexp from two given Regexps.
Actually, in the end, I will not do it for just two Regexps but a large number. I don't care about grouping or anything, I just want to know if a String matches one of a list of given Regexps. I could just check all of them in a loop, but that is too inefficient, that is why I need one Regexp to check the union.