Question: I am a newbie to Objective-C. I would like to display the current date and time in an alert view.

```
- (IBAction)postButtonPressed:(UIButton *)sender  {

    NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"MMM d, yyyy h:mm" options:0 locale:[NSLocale currentLocale]];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:formatString];

    NSString *todayString = [dateFormatter stringFromDate:[NSDate date]];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Posted" message:@"Your Message is posted on: @todayString" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [alert show];
      }

```

Answer: 
Because the split function separator is not included in the results.  

If you want it to remain as a split element enclose it in parenthesis 

```
string time = @"([0-9]{2}:[0-9]{2}(A|P)M)";

```

By the way, that's the reason that the 'A' and 'P' were left, because they were enclosed in parenthesis.
Use capturing groups.

```
string regex=@".+?(?:\b\d{2}:\d{2}(?:AM|PM)|$)";
MatchCollection matches=Regex.Matches(input,regex);
foreach(var match in matches)
    Console.WriteLine(match.Groups[0]);

```