If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > help with REGEXP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-05, 11:00
wardly wardly is offline
Registered User
 
Join Date: Dec 2004
Posts: 27
Exclamation 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.
Reply With Quote
  #2 (permalink)  
Old 01-26-05, 11:30
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-26-05, 11:40
wardly wardly is offline
Registered User
 
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] ?
Reply With Quote
  #4 (permalink)  
Old 01-26-05, 12:13
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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')
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-26-05, 12:16
wardly wardly is offline
Registered User
 
Join Date: Dec 2004
Posts: 27
Ok that worked erfectly, thanks so much for your help.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On