Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regexp for db query

    Hi,
    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!

    Thanks in advance for any thoughts,
    Dave

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This isn't regex but it's a way of doing what you want to do.

    PHP Code:
    $string '25504010';

    $length strlen($string);


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

    Alex
    Give me Rep if I was helpful and ignore if I wasn't ;)

    http://www.google.com <--use this before asking

    Nominate a Helpful Member



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •