Re: MySQL REGEXP functionality... any way to make this easier?
| From: | Martin Adler | Date: | Thu, 10 Oct 2002 09:15:15 +0000 |
| Subject: | Re: MySQL REGEXP functionality... any way to make this easier? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-22308@lists.php.net to get a copy of this message | ||
Hi,
unfortunately i can't help you much, but listen
you can make your pattern more readable if you
delete "[]" there's no need for classes in your pattern
SELECT * FROM ospd WHERE word REGEXP
'^a?p?e?$|^a?e?p?$|^p?e?a?$|^p?a?e?$|^e?a?p?$|^e?p?a?$';
? = one or none but if you need each letter then omit "?"
SELECT * FROM ospd WHERE word REGEXP '^ape$|^aep$|^pea$|^pae$|^eap$|^epa$';
this is the simplest way but it also matches aae, aaa, ppe, ppp ... and
probably not what you need
SELECT * FROM ospd WHERE word REGEXP '^[aep]{3}$';
I thnk you don't have another choice then to write each combination by
yourself
greet
martin
----- Original Message -----
From: "Xepherys" <xepherys@xepherys.net>
To: <php-db@lists.php.net>
Sent: Thursday, October 10, 2002 8:26 AM
Subject: [PHP-DB] MySQL REGEXP functionality... any way to make this easier?
> Right now, a sample query I might have would be...
>
> SELECT * FROM ospd WHERE word REGEXP '^([a]?[p]?[e]?)$|^[p]?[a]?[e]?$|^[a
> ]?[e]?[p]?$|^[p]?[e]?[a]?$|^[e]?[p]?[a]?$|^[e]?[a]?[p]?$';
>
>
> where basically I need to query every combination of a, p and e. This is
a
> pain, but for only three letter is not so bad. As you can see, this could
> become unruly with larger numbers of letters. Each instance of a letter
can
> only occur once. However, a letter may be duplicated and used once for
each
> instance. Hence the statement steps through... it could also be something
> like...
>
> SELECT * FROM ospd WHERE word REGEXP
> '^[a]?[a]?[e]?$|^[a]?[e]?[a]?$||^[e]?[a]?[a]?$';
>
> more easily written because one letter is used twice and can occure once
for
> each instance. Please let me know if you have any ideas.
>
>
> Jesse
> jesse.williams@xepherys.net
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>