I am trying to use regex to extract a substring from a given string. I am doing this in Scala:
val pattern = Pattern.compile("(Word)+")
val matcher = pattern.matcher("WordWordRestOfString")
matcher.group(1)
The desired output is "WordWord", however, I keep getting an IllegalStateException. I haven't really worked with Regex before, and cannot fully grasp how the matcher.group method works, but I have seen answers to questions suggesting the use of matcher.group(1).