View Full Version : Regex parsing

11-21-2003, 04:46 AM
I have a text database file which has entries like

//--First Record

|:010 Keyword1:itsvalue
:020 Keyword2:anothervalue
:030 Keyword3:thirdvalue
:500 Keyword500:somevalue

//Second Record
|:0610 Keyword1:value
Records are separated by the "|" symbol(OR)

How do I parse it so that I can separate each record and take the keyword's values

Keywords and values are like "LOCATION:someplace","EMPLOYEE:contract" etc.
Each line starts with a :linenumber and also the data will have : like for website address (http://)

Can anybody help please?

11-21-2003, 07:57 PM
ouch thats a nasty format , are you stuck with it ? , perhaps better to change the storage format if possible or is that not an option ?

its parsable but avoiding regex is always optimal... how big are the individual files ?

11-22-2003, 04:44 AM
Changing the format is not an option coz the file is supplied by somebody else and I have to work on the file.Each record consists of around 100 fields and the total file db size around 15mb

11-22-2003, 11:11 AM

While it would be possible, it could take a long long time to work with 15 megs of text. Reading the file would take a while, then you would have to split it. While it's possible its highly unpractical. unless you only need to do it once?

11-24-2003, 04:47 AM
I have already split each record to individual files.I was looking for some code to teach me how to parse through the records.Thanks for the suggestions