Reputation: 817
I have a CSV file which I'm trying to import to a SQL Server table. The file contains lines of 3 columns each, separated by a comma. The only problem is that some of the data in the second column contains an arbitrary number of commas. For example:
1281,I enjoy hunting, fishing, and boating,smith317
I would like to escape all occurrences of commas in each line except the first and the last, such that the result of this line would be:
1281,I enjoy hunting\, fishing\, and boating,smith317
I know I will need some type of regular expression to accomplish this task, but my knowledge of regular expressions is very limited. Currently, I'm trying to use Notepad++ find/replace with regex, but I am open to other ideas.
Any help would be greatly appreciated :-)
Upvotes: 0
Views: 275
Reputation: 167212
Okay, could be a manual stuff. Do this:
,
and replace it with \,
. Escape everything.^(.*)(\\,)
and replace it with $1,
.(\\,)(.*)$
and replace it with ,$2
.Worked for me in Sublime Text 2.
Upvotes: 2