NOT REGEXP

Description

NOT REGEXP is used to test whether a string does not match a specified regular expression.

If column_name does not match pattern, it returns TRUE. If it matches, it returns FALSE.

Syntax

  1. > column_name NOT REGEXP pattern

Explanations

  • column_name is the column to match.

  • pattern is the regular expression to apply.

Examples

  1. CREATE TABLE example (
  2. id INT AUTO_INCREMENT,
  3. text VARCHAR(255),
  4. PRIMARY KEY(id)
  5. );
  6. INSERT INTO example (text)
  7. VALUES ('Hello1'),
  8. ('Hello2'),
  9. ('World'),
  10. ('HelloWorld'),
  11. ('Hello_World'),
  12. ('example'),
  13. ('example1'),
  14. ('example2');
  15. mysql> SELECT * FROM example WHERE text NOT REGEXP '[0-9]';
  16. +------+-------------+
  17. | id | text |
  18. +------+-------------+
  19. | 3 | World |
  20. | 4 | HelloWorld |
  21. | 5 | Hello_World |
  22. | 6 | example |
  23. +------+-------------+
  24. 4 rows in set (0.00 sec)