0

I had this regular expression:

preg_match("|[\|()<>%*+=]|(=)+(!)|[-]{2}|", $status, $array);

that generates this warning

Warning: preg_match(): Unknown modifier '(' in...

I know that is a problem of \ but I don't know where to put them.

Mat
  • 202,337
  • 40
  • 393
  • 406

2 Answers2

1

The problem is that you are using | as the delimiter for the pattern, so the second | ends the pattern and the ( is interpreted as a modifier. Do one of these, depending on if you need the | at the beginning and end:

preg_match("/|[\|()<>%*+=]|(=)+(!)|[-]{2}|/", $status, $array);
preg_match("/[\|()<>%*+=]|(=)+(!)|[-]{2}/", $status, $array);
Lars Ebert
  • 3,487
  • 2
  • 24
  • 46
0

The is some problems... Let see:

Yours:

  "|[\|()<>%*+=]|(=)+(!)|[-]{2}|"
   ^ first problem not needed as is an OR and there is nothing before it
       ^ you have to scape the parentesis all of it
            ^ you have to scape the asterisk
                               ^unecessary there is nothing after

So the result would be:

  "/[\|\(\)<>%\*+=]|(=)+(!)|[-]{2}/"
Jorge Campos
  • 22,647
  • 7
  • 56
  • 87