如何在mysql REGEXP中转义方括号?

时间:2023-01-21 21:42:35

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:

我有视频嵌入代码存储在数据库表中。我们使用多种视频源,包括YouTube,Viddler和本地存储的Flash文件。我需要找到闪存文件的所有记录。闪存记录的正文字段如下所示:

[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

39 - 从regexp获得错误'括号([])不平衡'

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

如果它是我正在寻找的第一个角色,我怎么能逃脱支架?

1 个解决方案

#1


8  

You have to use two backslashes.

你必须使用两个反斜杠。

regexp '^\\[swf'

#1


8  

You have to use two backslashes.

你必须使用两个反斜杠。

regexp '^\\[swf'