EmmyS
EmmyS

Reputation: 12138

How do I escape square brackets in mysql REGEXP?

I have video embed code stored in a database table. We use multiple video sources, including YouTube, Viddler, and locally-stored flash files. I need to find all the records with flash files. The body field for a flash record looks like this:

[swf file="/sites/default/files/lecture-video/2010_02_beier_schanzer.swf" width="702" height="560"]

I was hoping to do something like this:

SELECT * FROM `node_revisions` inner join node on node_revisions.nid = node.nid where node.type = "video" and node_revisions.body REGEXP "^[swf"

but got the following error:

39 - Got error 'brackets ([ ]) not balanced' from regexp

How can I escape the bracket when it's the first character I'm looking for?

Upvotes: 13

Views: 11286

Answers (1)

Nicola Cossu
Nicola Cossu

Reputation: 56397

You have to use two backslashes.

regexp '^\\[swf'

Upvotes: 23

Related Questions