Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2004
    Posts
    27

    Exclamation Unanswered: help with REGEXP

    Howdy folks,

    Ok i've never been good with regexp but need some help. What i need to do is get a query to a database that looks at the last number of a sequance of numbers and compares it to a prefined number that will be passed via PHP.

    So for example i have a variable (in php) contianing 1,2 and need to find any results in the table base that has a sequance of numbers in a field that can contain anywhere from 5 - 7 numbers. (e.g. 12345 or 123456 or 1234567).

    What i do know is that i can find the last digit using the $ but am lost trying to figure out how to get the query put together under this situation.

    Any help would be very much appreciated as i need to get this done asap.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    please rephrase the question

    your variable contains '1,2' and you want to find that string where? does the found column value have to have 5-7 digits, or will you also want to see values that might have fewer?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2004
    Posts
    27
    Sorry for the lack of information.

    The field will contain strings of number ranging from 5 - 7 digits long, possably more but not fewer then 5. He's a mock up of the database field.

    ID--NUMBER-------
    1| 123452
    2| 123456
    3| 12345
    4| 1234567
    5| 123456
    6| 1234567
    7| 12345
    -------------------

    All i realy need is to locate any numbers in the field that end with a particular number. So in the example would be 1 or 2 (these will change with PHP but will always be 2 numbers).

    The query will return the entire record and not just this number. I'm using it in a where clause to reduce the overall number of returns on the query. So above if i was looking for any records with the numbers 7 or 8 i would retunr the ID's 4 and 6 and none of the other records.

    I'm not sure i totaly understand what your asking for i hope that was it.

    I'm assuming something like ^[0-9]$[1|2] ?

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    well if the field will contain strings of numbers, do you really need to use regexp to verify that it contains a string of numbers?

    if all you want is to check the last digit, try this --

    ... where right(number,1) in ('7','8')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Dec 2004
    Posts
    27
    Ok that worked erfectly, thanks so much for your help.

Posting Permissions

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