I have a simple regex pattern and a string. The regex pattern is (\d*)\*(C.*) and the string is 32*C1234*3.
I want to extract the values 32 and C1234*3 from that string using that regex pattern.
I can achieve that in Perl using the following code:
my $x = "32*C1234*3";
if ( my ($x1, $x2) = $x =~ /(\d*)\*(C.*)/ ) {
print "x1 = $x1, x2 = $x2\n";
} else {
print "No match\n";
}
The following is my attempt using Scala 2.11:
val s = "32*C1234*3"
val re = """(\d*)\*(C.*)""".r
(r findFirstIn s).toList
When I run this, I get a single value (and it is the original list followed by empty character) instead of 32 and C1234*3. How do I fix the scala code?
(re findFirstIn ...? I don't understand what your problem is, it returnsList(32*C1234*3*)as expected?s.split("[*]", 2)to split on the first*.