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

Question :

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

Answer :

I have this gigantic ugly string:

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  

I’m trying to extract pieces from it using regex. In this case, I want to grab everything after Project Name up to the part where it says J0000011: (the 11 is going to be a different number every time).

Here’s the regex I’ve been playing with:

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

The problem is that it doesn’t stop until it hits the J0000020: at the end.

Read More  How many ServiceContracts can a WCF service have?

How do I make the regex stop at the first occurrence of J[0-9]{7}?

,

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

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

That’s the answer My regex is matching too much. How do I make it stop?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you

Read More  Assignment inside Perl ternary conditional operator problems