what is symbol for "AND" in REGEXP ?/

Discussion in 'PHP' started by jacka, Aug 16, 2007.

  1. #1
    Hi
    I am trying to look through mysql database and pick items that stay with "t2.5" and end with "DL".

    I have googled for hours (honest) but can not find the symbol for "AND" although i have found for or, which is "|".
    What i wnat it to say is:

    
    
    select * from pn_quarkpage where part_number REGEXP '^T2.5 AND (DL$)';
    
    
    Code (markup):
    Many thanks.

    jacka
     
    jacka, Aug 16, 2007 IP
  2. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You're not quite understanding how a regular expression works.

    The statement you require is....

    select * from pn_quarkpage where part_number REGEXP '^T2.5.*DL$';

    (except you should probably escape the "." between the 2 and 5)

    "." means any character in a regular expression, and ".*" means any character, repeated any number of times. So what you want is anything that starts with T2.5, then has any characters following it, then ends with DL. There is no "AND" as such in this context.

    Consider it in the same way you would a dir search command. If you wanted to list files that started with T2 and ended in DL you'd do....

    DIR T2*DL

    It's very similar

    The only thing wrong with the expression I've given you is that it would return T2<anything>5. You need to escape the "." there but wasn't sure what the escape character is in a MYSQL regular expression. Anyone got any ideas?
     
    ecentricNick, Aug 16, 2007 IP
  3. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi ecentricNick

    Once agian you have come to my aid.

    The scape character is "\", and yoru code and explanation works a treat.

    many thanks
    keep up the good work.
    Maybe one day I will be as good as you to help others.
    CHeers mate
     
    jacka, Aug 16, 2007 IP
  4. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You're welcome - glad to be of help
     
    ecentricNick, Aug 16, 2007 IP