Regex Problem in PHP

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2011-01-04T05:56:46Z Indexed on 2011/01/04 6:54 UTC
Read the original article Hit count: 403

Filed under:
|

I'm attempting to utilize the following Regex pattern:

$regex = '/Name: [a-zA-Z ]*] [0-9]/';

When testing it in Rubular, it works fine, but when using PHP the expression never returns true, even when it should. Incidentally, if I remove the "[0-9]" part, it works fine. Is there some difference in PHP's regex syntax that I'm overlooking?

Edit: I'm looking for the characters "Name:" then a name containing any number of letters or spaces, then a "]", then a space, then a single number. So "Name: Chris] 5" would return true and "Name: Chris] [lorem ipsum]" should return false.

I also tried escaping the second bracket "\[" but this did not fix the problem.

© Stack Overflow or respective owner

Related posts about php

Related posts about regex