At 10:49 +0100 11/8/05, Jigal van Hemert wrote:
Lindsey wrote:
ok thanks, then i know!
but do you know how to use the * in regexp searches. err what i
mean if i want to search for * and not use it as asterix?
i have tried \* but that did't work, it just does the same as *.
The manual comes again to the rescue ;-)
Appendix G [1] tells us:
" To use a literal instance of a special character in a regular
expression, precede it by two backslash (\) characters. The MySQL
parser interprets one of the backslashes, and the regular expression
library interprets the other. "
So:
SELECT 'GRANDS*N' REGEXP 'S\\*N'; -> 1
[1] http://dev.mysql.com/doc/refman/5.0/en/regexp.html
Um, no. :-)
In this case, * is to be used as a special character, you don't want
to match it literally.
Also, * means "any number of the previous thing," not "any number of anything."
The pattern you're looking for is .* (. = match any character, .* = match
any number of any character).
Also, if S must be at the beginning and Y at the end, you need to
use ^ and $ to anchor the beginning and end of the match. So
the pattern you want is '^S.*Y$'.
mysql> select 'SAMSUNG' regexp '^S.*Y$';
+---------------------------+
| 'SAMSUNG' regexp '^S.*Y$' |
+---------------------------+
| 0 |
+---------------------------+
1 row in set (0.00 sec)
mysql> select 'SIEMENS' regexp '^S.*Y$';
+---------------------------+
| 'SIEMENS' regexp '^S.*Y$' |
+---------------------------+
| 0 |
+---------------------------+
1 row in set (0.00 sec)
mysql> select 'SONY' regexp '^S.*Y$';
+------------------------+
| 'SONY' regexp '^S.*Y$' |
+------------------------+
| 1 |
+------------------------+
1 row in set (0.00 sec)
--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]