SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with REGEXP

    Hi,

    I have a table in which one column stores some alphanumeric values
    I am trying to get a count of records in my database that have a particular format (and those that don't)
    The column has values in the following formats
    AAxxxxxxxxxAAAAA
    and
    xxxxxxxxxxxxxxxx

    where AA are alpha characters and xxxx are numeric characters
    I tried the following to get the count of ones formated like AAxxxxxxxxxAAAAA
    I also tried replacing the REGEXP with like
    but still I am getting 0 all the time

    Code MySQL:
    SELECT count( * ) 
    FROM mytable
    WHERE myfield
    REGEXP '[A-Z]{2}-[0-9]{9}-[A-Z]{5}';

    Any help would be appretiated
    Thanks

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,332
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    You are on the right track with the RegExp here. But you must remove the dashes. They will be interpreted literally, and based on what you describe your data does not contain any dashes.
    Code:
    [A-Z]{2}[0-9]{9}[A-Z]{5}
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow, lol
    Thank you!!!


Bookmarks

Posting Permissions

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