The _traveler
The _traveler

Reputation: 131

Search/replace in block selection in Notepad++

Is there a way to limit search/replace only to a columnar block selection in Notepad++?

Here is what I am trying to do:

Upvotes: 3

Views: 6778

Answers (6)

Adithya
Adithya

Reputation: 2975

I might be late to answer this query but it could be helpful for anyone stumbling upon this question in future.

As per this - i was able to select data in column mode. Place your cursor to the start of the text. Then press Shift+Alt and continue to drag your mouse till your last selection.

Upvotes: 0

Himanshu Mistry
Himanshu Mistry

Reputation: 1

My search on internet, to to see weather notepad++ suports this; brought me here. I have used TextPad and confirm that it supports find-and-replace within column selected block. Also TextPad is free for personal use.

Upvotes: 0

Brandon Dutton
Brandon Dutton

Reputation: 1

You may not be able to Search/Replace within a columnar selection, but you can easily carry out your task within Notepad++. Use Find and Replace feature, with the Regular Expressions box checked.

If you want to remove quotes only from a target column, use the following regular expression in the Find field:

 (^([^,]*,){i})"([^,\n\r]*)"(.*$)

Replace i with the position of the target column minus 1.

(i.e.- Us 2 if you want quotes around the third column, 0 for the first column, etc)

In the Replace field use:

 \1\3\4

Clicking "Replace All" will strip quotes from the target column.


If you want to blow away all quotes surrounding each element in your csv without prejudice, use the following regular expression in the Find field:

 ((?<=,)|(?<=^))"(.*?)"((?=$|,))

In the Replace field use:

 \1\2\3

Clicking Replace All will strip quotes form the columns.


Example

Since you didn't provide an example csv file, I'll walk through my own working example. Below is my csv:

 "0","1","2","3","4","5","6","7","8","9"
 "10","11","12","13","14","15","16","17","18","19"
 "20","21","22","23","24","25","26","27","28","29"
 "30","31","32","33","34","35","36","37","38","39"
 "40","41","42","43","44","45","46","47","48","49"
 "50","51","52","53","54","55","56","57","58","59"
 "60","61","62","63","64","65","66","67","68","69"
 "70","71","72","73","74","75","76","77","78","79"
 "80","81","82","83","84","85","86","87","88","89"
 "90","91","92","93","94","95","96","97","98","99"
 "100","101","102","103","104","105","106","107","108","109"
 "110","111","112","113","114","115","116","117","118","119"
 "120","121","122","123","124","125","126","127","128","129"
 "130","131","132","133","134","135","136","137","138","139"
 "140","141","142","143","144","145","146","147","148","149"
 "150","151","152","153","154","155","156","157","158","159"
 "160","161","162","163","164","165","166","167","168","169"
 "170","171","172","173","174","175","176","177","178","179"
 "180","181","182","183","184","185","186","187","188","189"
 "190","191","192","193","194","195","196","197","198","199"

If I wanted to remove quotes from the second column, I would use the below Find and Replace fields

 (^([^,]*,){1})"([^,\n\r]*)"(.*$)

 \1"\3"\4

Clicking Replace All yields the below result:

 "0",1,"2","3","4","5","6","7","8","9"
 "10",11,"12","13","14","15","16","17","18","19"
 "20",21,"22","23","24","25","26","27","28","29"
 "30",31,"32","33","34","35","36","37","38","39"
 "40",41,"42","43","44","45","46","47","48","49"
 "50",51,"52","53","54","55","56","57","58","59"
 "60",61,"62","63","64","65","66","67","68","69"
 "70",71,"72","73","74","75","76","77","78","79"
 "80",81,"82","83","84","85","86","87","88","89"
 "90",91,"92","93","94","95","96","97","98","99"
 "100",101,"102","103","104","105","106","107","108","109"
 "110",111,"112","113","114","115","116","117","118","119"
 "120",121,"122","123","124","125","126","127","128","129"
 "130",131,"132","133","134","135","136","137","138","139"
 "140",141,"142","143","144","145","146","147","148","149"
 "150",151,"152","153","154","155","156","157","158","159"
 "160",161,"162","163","164","165","166","167","168","169"
 "170",171,"172","173","174","175","176","177","178","179"
 "180",181,"182","183","184","185","186","187","188","189"
 "190",191,"192","193","194","195","196","197","198","199"

Upvotes: 0

RJCL
RJCL

Reputation: 357

sort of a late reply but... I had the same problem when I moved to a new machine with Notepad++ installed. Previously, I was using a text editor called Boxer that had this feature, which I found invaluable. Its not free-ware however.

Upvotes: 0

Niklaus Messerli
Niklaus Messerli

Reputation: 96

I know, this probably won't help you any more, but I just had the same problem and stumbled across this question.

I found moving the block in question to a new file and performing the find/replace there works quite decently. When moving the block back, be sure to select it in block mode (see this question).

Upvotes: 3

Charles Barkles
Charles Barkles

Reputation: 17

No. Another editor may have this feature.

Upvotes: 0

Related Questions