Need help on Regex

Splash Forums PrettyFaces Users Need help on Regex

This topic contains 1 reply, has 2 voices, and was last updated by  Christian Kaltepoth 4 years, 7 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18870

    cobepnmrac
    Member

    I want to split the string : “FNAME,”STREET,PLACE”,ADDR2,XYZ”

    Desired O/p : (Comma seperated values but ignore the , when it is between “”)

    FNAME

    “STREET,PLACE”

    ADDR2

    XYZ

    I seach on internet and find : “,(?=([^”]*”[^”]*”)*[^”]*$” this regex working fine for me but I am not able to understand this. Also please suggest if there is any better way of doing this.

    Thanks in Advance

    #23145

    I’m not sure if you should use regular expressions in this case. This really gets complicated.

    The format you are trying to parse looks a lot like CSV. There are many free libraries out there that can parse CSV files. Perhaps you should check if there is any library that fits your needs.

    But you could also do the parsing yourself. This should be very easy if you read character by character. Whenever you hit a ", switch into some kind of string-literal mode. If you find a , and are not in string-literal mode, you found a new column. That’s just a simple state machine. :)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Comments are closed.