Re: MySQL Regular expression
| From: | Ignatius Reilly | Date: | Thu, 09 Oct 2003 12:09:03 +0000 |
| Subject: | Re: MySQL Regular expression | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-30923@lists.php.net to get a copy of this message | ||
Problem is, REGEX will only test for a match, not returning anything other
than 0|1
You can instead:
1. Use a UDF doing just that (counting occurences in a string):
http://www.tsc.ro/free/
(haven't tried it myself, because no Windows dll available)
2. Replace successively all figures by '' and count length:
SELECT
CHARACTER_LENGTH(
REPLACE(
REPLACE(
mycol,
'1', ''
) ,
'2', ''
)
)
... and recurse - ugly, but works
3. Try successive REGEX matching the number of ',' with an integer
4. Best, of course, normalize your DB. But this may not be an option...
HTH
Ignatius
_________________________
----- Original Message -----
From: "O Franssen" <twisteddesign@eircom.net>
To: <php-db@lists.php.net>
Sent: Thursday, October 09, 2003 1:49 PM
Subject: [PHP-DB] MySQL Regular expression
> I'm not a 100% sure if this is the correct list for the following
> question, so I shall apologise beforehand if I upset any one.
>
> Now, I have a field in my database table in the following format:
>
> 100,30,443, etc.
> Representing prices for 52(53) weeks of the year and comma delimited.
>
> Now I need to check the price for a given week within my query.
> The problem however is that the week number is variable.
>
> Is there a way to count the number of non-consecutive occurances of a
> character, in this case commas, in a regular expression?
>
> I know ,{#} will check for # occurances of consecutive occurances of
> #, but is there a similar way to check for non-consecutive?
>
> Thank you in advance.
>
> --
> Regards,
> Owen Franssen
> Twisted Design
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>