aspnetguy Posted October 31, 2007 Report Share Posted October 31, 2007 I have a string that I need to split with a Regular expression.The sample string would be like this: 4533,"this is a descrption with a , in it"I need to split by comma (,) but not if the comma is within double quotes (")Something like /[^(".*,.*")]/ will not match commas in double quotes but I don't know how to get it to also match commas outside double quotes.Thanks. Link to comment Share on other sites More sharing options...
boen_robot Posted October 31, 2007 Report Share Posted October 31, 2007 How about /[^(".*,.*")],/ Just to be clear, what the environment? JavaScript? I'm asking because I've seen two ways to make a negative match. One is that way, and the other was something like (!?,) (in that sample, the regex matches anything but any comma) Link to comment Share on other sites More sharing options...
aspnetguy Posted October 31, 2007 Author Report Share Posted October 31, 2007 it is in C#, I'll give it a try Link to comment Share on other sites More sharing options...
aspnetguy Posted October 31, 2007 Author Report Share Posted October 31, 2007 nope the negative match works but then the , at the end of the pattern matches all commas Link to comment Share on other sites More sharing options...
aspnetguy Posted October 31, 2007 Author Report Share Posted October 31, 2007 Never mind I found a solution ,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\")) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now