'Function preg_match() is not finding the end of line appropriately

I'm parsing through information in a file coming from a console, at the end of each line is the date, but the line may also have the date already listed in it. The input lines look like this:

 00029 --> Ticket Received in QUEUE11 by ABCDE on 04/11/2013 at 11:   4/11/2013 
 00030 07:12.                                                         4/11/2013 

(There's a space before each line number and at the end of the line).

My regex in my foreach loop looks like this:

if (preg_match("/\s\d{5}\s(.+?)\d{1,2}\/\d{1,2}\/\d{1,4}\s\n/", $line, $match))
{
    $note = $match[1];
}

The regex is working in The Regex Coach and I can't find any reason why it won't work in my code. With the \n there, it matches no line. Without it, it cuts off before the first date.

I also tried \r and it behaves the same as having nothing. I'm looking for the final output to look like this once I've echoed $note in the loop.

Ticket Received in QUEUE11 by ABCDE on 04/11/2013 at 11:
07:12.

What am I missing?



Solution 1:[1]

Make the spaces at the end optional:

if (preg_match("/\s\d{5}\s(.+?)\d{1,2}\/\d{1,2}\/\d{1,4}\s*\n/", $line, $match))
//                                                here ___^
{
    $note = $match[1];
}   

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Toto