I'm looking for a way to capture a string out of a larger string that matches a regex. I looked into the String class, but there is nothing there to help. I can't believe a function like this isn't included in the class. I can match on it, but can't extract it:
Originally posted by Tyler Jordan: Thanks! The function group() from matcher fits the bill.
But your regex doesn't. The '^' and '$' anchors force the regex to match the entire string, but you obviously want to pluck out matching substrings. Also, there's no need for the "||" (or even "|") in the first character class; OR is implicit, and in fact a pipe just matches a pipe when you use it in a character class. Putting it all together: