开发者

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?


You have to use two backslashes.

regexp '^\\[swf'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜