简体   繁体   English

MySQL正则表达式匹配

[英]MySQL regular expression matching

I have an array that contains some sting values that need to be matched in a similar fashion to or where. 我有一个包含一些字符串值的数组,这些字符串值需要以类似的方式匹配或在哪里匹配。 The array looks like this: 该数组如下所示:

array('IS','KG','BO BB AF', 'MA')

When using a where clause I can match the 1st second and third values 当使用where子句时,我可以匹配第一个第二和第三个值

SELECT * WHERE product_code LIKE 'IS'

but the 3rd value 'BO BB AF' needs to be matched like this 但是第三个值“ BO BB AF”需要这样匹配

SELECT * WHERE product_code LIKE 'BO' or 'BB' or 'AF'

Is this possible to do with a single MySQL statement with a regular expression or will I have to break up the string and loop through it? 这可能与带有正则表达式的单个MySQL语句一起执行还是我必须分解字符串并循环遍历?

我不确定此查询的可行性,但可以使用类似REGEXP

SELECT * WHERE product_code REGEXP 'IS|KG|BO|BB|AF|MA'

Use REGEXP operator for such case: 在这种情况下,请使用REGEXP运算符:

SELECT * WHERE product_code REGEXP 'IS|KG|BO|BB|AF|MA';

http://dev.mysql.com/doc/refman/5.7/en/regexp.html http://dev.mysql.com/doc/refman/5.7/zh-CN/regexp.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM