匹配字符串中包含特定字符或字符串的记录
SELECT*FROM table_name WHERE column_name REGEXP 'pattern';
例如,要查找包含单词"example"的记录:
SELECT*FROM my_table WHERE my_column REGEXP 'example';
匹配字符串中以特定字符或字符串开头或结尾的记录
SELECT*FROM table_name WHERE column_name REGEXP '^pattern'OR column_name REGEXP 'pattern$';
例如,要查找以字母"E"开头的记录或以数字"123"结尾的记录:
SELECT*FROM my_table WHERE my_column REGEXP '^E'OR my_column REGEXP '123$';
匹配字符串中特定模式的记录
SELECT*FROM table_name WHERE column_name REGEXP 'pattern1|pattern2';
例如,要查找包含单词"example"或"sample"的记录:
SELECT*FROM my_table WHERE my_column REGEXP 'example|sample';
匹配字符串中特定字符范围的记录
SELECT*FROM table_name WHERE column_name REGEXP '[a-z]';
例如,要查找包含任何小写字母的记录:
SELECT*FROM my_table WHERE my_column REGEXP '[a-z]';
匹配字符串中特定字符集合的记录
SELECT*FROM table_name WHERE column_name REGEXP '[abc]';
例如,要查找包含字母"a"、"b"或"c"的记录:
SELECT*FROM my_table WHERE my_column REGEXP '[abc]';
以上是MySQL中REGEXP函数的一些常用用法,可以根据实际需求灵活运用。