We help IT Professionals succeed at work.

Im trying to find a vert simple pattern why isnt its working

Im trying to find a vert simple pattern in a text : all the text after the words comment:

and its not working anybody know why??
$message = preg_match('/Comments(.*?)/s',$row['message'],$matches);

Open in new window

Comment
Watch Question

Commented:
Remove ? from pattern and retry.

Author

Commented:
I always get comused in this one can you explain me the diffrence between (.)   (.*) (.*?) (*?)
Most Valuable Expert 2011
Top Expert 2015

Commented:
StingRaY is correct. The reason is because you specified that dot-star be minimal when you added the question mark. A minimal match means the least amount of characters that can form a match are returned. Since you don't have anything that follows the dot-star-question, the minimal amount of characters that can come after the word "Comments" is zero; so you don't receive any text that comes after that word.

Removing the ? makes the dot-star greedy, and the pattern will try to consume as many characters as it can before returning the match. In this case, the dot-star will return everything that comes after the word "Comments" if you remove the ? .
Most Valuable Expert 2011
Top Expert 2015
Commented:
(.)   -   Any character ( . ), saved to a capture group (parens)
(.*)  -  Zero-or-more ( * ) of any character ( . ), saved to a capture group (parens)
(.*?)  - Minimally ( ? ), zero-or-more ( * ) of any character ( . ), saved to a capture group (parens)
(*?)  - Invalid pattern.
Most Valuable Expert 2011
Top Expert 2015

Commented:
See my comment here for an example of the difference between the two:

    www.experts-exchange.com/Software/VMWare/Q_27412639.html#37020431

Commented:
Good explanation, kaufmed.

Author

Commented:
yes Thank you!
Most Valuable Expert 2011
Top Expert 2015

Commented:
Points to StingRaY: he nailed it in one shot  = )