SELECT vend_name FROM vendors WHERE vend_name REGEXP '.' ORDER BY vend_name;
The above statement results the following output:
+-----------------+ | vend_name | +-----------------+ | Hewlett Packard | | Apple | | Microsoft Inc. | +-----------------+
That did not work. .
matches any character, and so every row was retrieved.
To match special characters they must be preceded by \\
. So, \\-
means find and \\.
means find .
:
SELECT vend_name FROM vendors WHERE vend_name REGEXP '\\.' ORDER BY vend_name;
The above statement results the following output:
+-----------------+ | vend_name | +-----------------+ | Microsoft Inc. | +-----------------+
That worked. \.
matches .
, and so only a single row was retrieved. This process is known as escaping, and all characters that have special significance within regular expressions must be escaped this way. This includes .
, |
, []
, and all of the other special characters used thus far.