starts and ends with regular expressions

Discussion in 'PHP' started by jacka, Jul 9, 2008.

  1. #1
    Hi

    I wish to match any string, in a table, that starts with "NBC" and ends with "L".
    such as NBC62-L,NBCkhs-24L, etc.
    Any characters are allowed in between.
    I have come up with: REGEXP ^NBC+L$
    is this correct? I know how to use OR but don't know how to use and.

    Also can you tell me which command to use to display the data before I actually do the alteration to the MYSQL table, just to test that the correct fields in the table are selected.

    Many thanks for your help
    :confused::confused:
     
    jacka, Jul 9, 2008 IP
  2. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi
    Is this correct?
    REGEXP '^HPCGBK.*L$ '.
    I don't think it is but I must be very close.

    :confused:
     
    jacka, Jul 9, 2008 IP
  3. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't think you need regex for that. You should be able use LIKE 'NBC%L' where % matches any character any number of times.
     
    rodney88, Jul 9, 2008 IP