1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Aggh! RegEx: Quotes in QuotedStrings....

Discussion in 'Software' started by Hepath, 13 Aug 2007.

  1. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    Anyone able to help... I am parsing a csv file and wish to find the quoted strings (in addition to other things).

    {id:19852,name:'Fred's House',Number:68},

    currently the RegEx I have :
    {id:([\d]+),name:'\d([A-z \']+)

    This stops at the first apostrophe giving me up to "Fred"... To add the confusion the field 'may' also have a comm in it!!

    I'm sure there's a way of doing this...!

    Any help greatfully received.
     
    Last edited: 13 Aug 2007
  2. Fophillips

    Fophillips What's a Dremel?

    Joined:
    9 Oct 2006
    Posts:
    948
    Likes Received:
    1
    Your CSV file terminates fields at apostrophes, so you will need to escape the ones in the data. So, your CSV file would read:
    Code:
    {id:19852,name:'Fred\'s House',Number:68},
    And your regex would be:
    Code:
    {id:([\d]+),name:'\d([A-z ([^\\]\')]+)
    The extra [^\\] means not to include ones which are preceded by a \
    (untested)
     
  3. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    Will try that and let you know... thanks.
     

Share This Page