How do I tell the following regex to only find the FIRST match? The following code keeps finding all possible regex within the string.
i.e. I\'m looking only for the in
matcher.group(1)
will return the first match.
If you mean lazy matching instead of eager matching, try adding a ? after the + in the regular expression.
Alternatively, you can consider using something more specific than .+
to match the content between the brackets. If you're only expecting letters, numbers and a few characters then maybe something like [-A-Z0-9;_.]+
would work better?