<p>I have this gigantic ugly string:</p>
<pre class="lang-none prettyprint-override"><code>J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
J0000010: Project name: E:\foo.pf
J0000011: Job name: MBiek Direct Mail Test
J0000020: Document 1 - Completed successfully
</code></pre>
<p>I'm trying to extract pieces from it using regex. In this case, I want to grab everything after <code>Project Name</code> up to the part where it says <code>J0000011:</code> (the 11 is going to be a different number every time).</p>
<p>Here's the regex I've been playing with:</p>
<pre class="lang-none prettyprint-override"><code>Project name:\s+(.*)\s+J[0-9]{7}:
</code></pre>
<p>The problem is that it doesn't stop until it hits the <strong>J0000020:</strong> at the end.</p>
<p>How do I make the regex stop at the first occurrence of <code>J[0-9]{7}</code>?</p>

[{'answer_id': 22449, 'author': 'jj33', 'author_id': 430, 'author_profile': 'https://Stackoverflow.com/users/430', 'pm_score': 8, 'selected': True, 'text': "<p>Make <code>.*</code> non-greedy by adding '<code>?</code>' after it:</p>\n\n<pre><code>Project name:\\s+(.*?)\\s+J[0-9]{7}:\n</code></pre>\n"}, {'answer_id': 22457, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 4, 'selected': False, 'text': '<p>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.</p>\n\n<p>However, consider using a negative character class instead:</p>\n\n<pre><code>Project name:\\s+(\\S*)\\s+J[0-9]{7}:\n</code></pre>\n\n<p><code>\\S</code> means “everything except a whitespace and this is exactly what you want.</p>\n'}, {'answer_id': 22461, 'author': 'Hershi', 'author_id': 1596, 'author_profile': 'https://Stackoverflow.com/users/1596', 'pm_score': 1, 'selected': False, 'text': '<p>I would also recommend you experiment with regular expressions using "Expresso" - it\'s a utility a great (and free) utility for regex editing and testing.</p>\n\n<p>One of its upsides is that its UI exposes a lot of regex functionality that people unexprienced with regex might not be familiar with, in a way that it would be easy for them to learn these new concepts.</p>\n\n<p>For example, when building your regex using the UI, and choosing "*", you have the ability to check the checkbox "As few as possible" and see the resulting regex, as well as test its behavior, even if you were unfamiliar with non-greedy expressions before.</p>\n\n<p>Available for download at their site:\n<a href="http://www.ultrapico.com/Expresso.htm" rel="nofollow noreferrer">http://www.ultrapico.com/Expresso.htm</a></p>\n\n<p>Express download:\n<a href="http://www.ultrapico.com/ExpressoDownload.htm" rel="nofollow noreferrer">http://www.ultrapico.com/ExpressoDownload.htm</a></p>\n'}, {'answer_id': 22480, 'author': 'Svend', 'author_id': 2491, 'author_profile': 'https://Stackoverflow.com/users/2491', 'pm_score': 3, 'selected': False, 'text': '<p>Well, <code>".*"</code> is a greedy selector. You make it non-greedy by using <code>".*?"</code> When using the latter construct, the regex engine will, at every step it matches text into the <code>"."</code> attempt to match whatever make come after the <code>".*?"</code>. This means that if for instance nothing comes after the <code>".*?"</code>, then it matches nothing. </p>\n\n<p>Here\'s what I used. <code>s</code> contains your original string. This code is .NET specific, but most flavors of regex will have something similar.</p>\n\n<pre><code>string m = Regex.Match(s, @"Project name: (?&lt;name&gt;.*?) J\\d+").Groups["name"].Value;\n</code></pre>\n'}, {'answer_id': 51357203, 'author': 'Shailendra', 'author_id': 1556909, 'author_profile': 'https://Stackoverflow.com/users/1556909', 'pm_score': 0, 'selected': False, 'text': '<p>(Project name:\\s+[A-Z]:(?:\\\\w+)+.[a-zA-Z]+\\s+J[0-9]{7})(?=:)</p>\n\n<p>This will work for you.</p>\n\n<p>Adding (?:\\\\w+)+.[a-zA-Z]+ will be more restrictive instead of .*</p>\n'}]
['https://Stackoverflow.com/questions/22444', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/305/']