View Full Version : regexp for db query

02-21-2007, 04:31 AM
I'm trying to come up with a regular expression to use in a database query that, when given an input, will match itself and substrings of itself.
For example, say as my input I have: 25504010
Now I would like to query the DB for any of the following (every 2 digits stand for a different category):
25504010 (the input itself!)
255040 (the first substring I'm interested in)
2550 (another substring)
25 (another substring)

Is there a regex that can do this? I suppose I can always add a bunch of OR conditions to the DB query but this seems like something a regex can solve, I just can't think of the solution! :rolleyes:

Thanks in advance for any thoughts,

02-21-2007, 11:19 AM
This isn't regex but it's a way of doing what you want to do.

$string = '25504010';

$length = strlen($string);

for($i = $length; $i > 0; $i -= 2)
$substring = substr($string, 0, $i);
echo "$substring<br/>";

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum