0

I have a CSV text file in a similar layout to below

COL1, COL2, COL3, ADDRESS1, COL5, COL6, COL7
dsada34sdsad5asdas, dasd32sadasd232as, fioejwfw667eoefw, 1 Terrace Lane, goirgngniogri,giergrngernn, gireneogner

I am trying to use a regex to put quotation marks around everything in ADDRESS1, so the only way I can seem to find the contents between is working out that after the 3rd comma is where my address starts and 3 commas back from the end is where my address ends.

I've currently used ^([^,]),([^,]),([^,]*), which selects from the start of each line to the 3rd comma. But replacing this then deletes all of that selection rather than appending a " mark to the start of address. Then I haven't quite figured out how to do the same but in reverse from the end of each line so I assume it will be a 2-step process.

UPDATE

ewwefeuuiofew99,6743964398hfjkef,gfbweifgbewifew665465,PARTOFADDRESS1,,,,, PARTOFADDRESS2,,, PARTOFADDRESS3,PARTOFADDRESS4, PARTOFADDRESS5, PARTOFADDRESS6,098304830gdsgsd,2014-08-08 00:00,,Yes

As you can see there are alot of commas floating throughout the data (unfortunately that's how I got it) so in your example it only highlights PARTOFADDRESS1.

1 Answer 1

2

Have a try with:

Find what: ^((?:[^,]+,){3})([^,]+)
Replace with: $1"$2"

update according to comment:

Is that what you want?

Find what: ^((?:[^,]+,){3})(.+)((?:,[^,]*){3})$
Replace with: $1"$2"$3

Sign up to request clarification or add additional context in comments.

3 Comments

Works to an extent, let me try to clarify my dataset a bit more. I will amend my question with a new example
I believe that it's 3 forward and 4 commas back from the end.
Using your edited version I just updated the second number to 4 and it seems to do what I want! Excellent!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.