Regular expression error in PHP

Asked

Viewed 259 times

4

Could anyone tell me why this regular error expression in PHP?

/:[^\/\\]*/

She’s being used this way:

return '/' . preg_replace('/:[^\/\\]*/', '([^\/]*)', $value) . '/';

I am trying to "break" one against bar with another but PHP behaves as if breaking the "]" character and returns the error: "Compilation failed: Missing terminating ] for Character class".

There is another way for me to specify a literal counter bar in a regular PHP expression?

  • Escape the backslash /:[^\\/\\\\]*/

2 answers

4


3

  • So I’m trying to create a regular "mutant" expression, I ask for a regular URL based on it to pick up occurrences in another, but when I use a regular expression and try to escape one against the wrong bar ('/[\\]/') PHP interprets it as if I were breaking the "]"...

  • That doesn’t solve it? $value = "http://primeseven.com.br"; $replaced = stripcslashes($value) var_dump($replaced)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.