Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Regex parsing

  1. #1
    New Coder
    Join Date
    Jul 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Regex parsing

    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?

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,047
    Thanks
    10
    Thanked 93 Times in 91 Posts
    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 ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Jul 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts


    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?

  • #5
    New Coder
    Join Date
    Jul 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

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