7

I had that test that worked fine :

if (ereg("([0-9]{2})[-./]([0-9]{2})[-./]([0-9]{4})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $dateToTest, $tab) == false)

and as ereg is deprecated, I have replaced that test with this one :

if (preg_match("/([0-9]{2})[-./]([0-9]{2})[-./]([0-9]{4})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $dateToTest, $tab) == false)

But I get the following error :

Warning: preg_match() [function.preg-match]: Unknown modifier '.' in ..................

What is the problem and how may I solve it ?

Oliver
  • 23,072
  • 33
  • 138
  • 230

3 Answers3

10

The problem is the delimiter / because you use it in your regexp again.

You have to escape it \/ or use another delimiter like @:

if (preg_match("@([0-9]{2})[-/.]([0-9]{2})[-/.]([0-9]{4})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})@", $dateToTest, $tab) == false)

See the example #3 in the Docu. There is also a manual about delimiters.

PiTheNumber
  • 22,828
  • 17
  • 107
  • 180
4

You have unescaped slashes in the expression. Either change / to \/ or use a different delimiter such as @ to start the expression.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0

the error is here /.. i don't know what do you mean by this regexp, so you can change it to . or \.

k102
  • 7,861
  • 7
  • 49
  • 69