Regex: Corrct expression to use.

This is a discussion on Regex: Corrct expression to use. within the C++ Programming forums, part of the General Programming Boards category; Hi I'm looking for a fast expression to parse a file which contains potentially millions of records such as the ...

  1. #1
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788

    Regex: Corrct expression to use.

    Hi

    I'm looking for a fast expression to parse a file which contains potentially millions of records
    such as the following:

    Code:
    "363111000686","923028199557","923456973171","03-01-2008 09:27:39","32"\n
    I've come up with this:
    Code:
    ([^,\"\n])+
    Now I'm no regex fundi, so any help would be highly appreciated.

    Thanks

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    What, exactly, do you want it to find?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Hi

    Basically, everything between the delimiter which, in this case is a ','.
    The fields themselves may have extra delimiters which, in this case is a '"'.

    So the matching should be:

    (1) 363111000686
    (2) 923028199557
    (3) 923456973171
    (4) 03-01-2008 09:27:39
    (5) 32

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Could you ever have a value such as " Foo, Bar"?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #5
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Hi

    Theoretically, yes! But the fields in a delimited file should not contain the delimiter themselves,
    so the parsing might fail when that happens, which may be okay.

    Is there a way to use groups properly if I knew how many fields there are in a record,
    as well as their respective extra delimiter characters?
    eg.
    Code:
    %363111000686%,$923028199557$,923456973171,03-01-2008 09:27:39,'32'\n
    If I know this beforehand, could i build an optimized expression?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with regex expression
    By pippo in forum C++ Programming
    Replies: 7
    Last Post: 01-19-2009, 12:14 AM
  2. Help with making a Math Expression DLL
    By MindWorX in forum C Programming
    Replies: 19
    Last Post: 07-19-2007, 11:37 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 08:15 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21