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 could also use trim() function to remove [] signs from customer column: SELECT c. *, cp. * FROM customer c LEFT JOIN customer_products cp ON trim(trailing ']' from trim(leading '[' from c.
To escape square brackets in LIKE you can use another square bracket to escape the original square bracket or use a custom escape character using the ESCAPE keyword in LIKE clause.
Basically, LIKE does very simple wildcard matches, and REGEX is capable of very complicated wildcard matches. In fact, regular expressions ( REGEX ) are so capable that they are [1] a whole study in themselves [2] an easy way to introduce very subtle bugs.
You have to use two backslashes.
regexp '^\\[swf'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With