I’ve been having problems extracting the value of a Regex in a String. I have a string with several regex expressions and I need to get the value of each expression’s match. The thing is though, it’s not returning the last match correctly. For example:
Regex Pattern: I play (\S+.*?) and (\S+.*?)
String: I play the guitar and the bass
The program is returning the value of the first expression as “the guitar” but it’s returning the value of the second expression as “the” instead of “the bass”. Is there a way to fix this?
Try:
I play (\S+.*) and (\S+.*).