SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: help with REGEXP

  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    15
    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
    Community Advisor silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    1,639
    Mentioned
    98 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}

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    15
    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
  •