My regex is matching too much. How do I make it stop?

Using non-greedy quantifiers here is probably the best solution, also because it is more efficient than the greedy alternative: Greedy matches generally go as far as they can (here, until the end of the text!) and then trace back character after character to try and match the part coming afterwards.

However, consider using a negative character class instead:

Project name:\s+(\S*)\s+J[0-9]{7}:

\S means “everything except a whitespace and this is exactly what you want.


Make .* non-greedy by adding '?' after it:

Project name:\s+(.*?)\s+J[0-9]{7}:

Tags:

Regex