Thread: Regex: Corrct expression to use.

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

  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
    Chappell Hill, Texas
    Posts
    2,332
    Could you ever have a value such as " Foo, Bar"?
    Mainframe assembler programmer by trade. C coder when I can.

  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, 01: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, 09:15 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM