Page 1 of 1

preg_match square brackets

Posted: Wed Oct 28, 2009 4:33 pm
by MrRSMan

Code: Select all

preg_match("~.*word.*~i")
The code above works fine when I'm matching "word". However, now I want to match this

],[],[]];

But PHP doesn't seem to like me using these special characters. How can I preg_match them?

Thanks

Re: preg_match square brackets

Posted: Wed Oct 28, 2009 4:37 pm
by pickle
Escape them with "\"

Re: preg_match square brackets

Posted: Wed Oct 28, 2009 5:04 pm
by MrRSMan
pickle wrote:Escape them with "\"
Could you show me the code please? I' think I've tried this and it didn't work- or maybe I just got it wrong.

Re: preg_match square brackets

Posted: Wed Oct 28, 2009 6:20 pm
by Mirge
\[

\]

Re: preg_match square brackets

Posted: Wed Oct 28, 2009 8:03 pm
by requinix