preg_match square brackets

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MrRSMan
Forum Newbie
Posts: 20
Joined: Sun Feb 03, 2008 8:11 am

preg_match square brackets

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: preg_match square brackets

Post by pickle »

Escape them with "\"
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
MrRSMan
Forum Newbie
Posts: 20
Joined: Sun Feb 03, 2008 8:11 am

Re: preg_match square brackets

Post 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.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: preg_match square brackets

Post by Mirge »

\[

\]
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: preg_match square brackets

Post by requinix »

Post Reply