is it possible to highlight all strings based on the field delimiter?
-
so i have a lot of data that contains a header and values of different sizes. I want to easily locate the values under each header. I can import it into a spreadsheet but that takes a lot of time. Is there a quicker way to achieve this with notepad++?
example:
field1;field2;field3;field4;field5
1;2;3;4;5
5;4;3;2;1I want to be able to select “field4” and “4” and “2” will also be highlighted. They are all the strings after the 3rd field delimiter and vice versa. this will be a great visual clue.
thanks and appreciate any help .
-
Here’s kind of a hacky way to do it:
Do a MARK operation (see the Find window tab for “mark”).
Put
(?-s)^([^;]+;){FIELDMINUS1}\K([^;\r\n]+)
in the find what box (but see below first!)
Tick Wrap around box
Tick Regular expression search modeSee where I put
FIELDMINUS1
in the find what? Put a real number in there. So to continue your example if you want field 4 you would put a 3 in for FIELDMINUS1, to wit:(?-s)^([^;]+;){3}\K([^;\r\n]+)
Then press the Mark All button.
-
Hi Alan, thanks it worked! and based on the code; i just have to replace ‘;’ with ‘,’ for CSV files.
-
I worked on it further and came up with something more generic:
(?-s)^(?:.*?(;|,|\t)){FIELDMINUS1}\K(?:.*?)(?=(?1)|\R|\z)
It will match various delimiters:
;
or,
ortab
. To add or remove delimiters, just change this part of it:(;|,|\t)
It will also work (and highlight nothing) for a field if that field position occurs in the middle of two consecutive field delimiters (also stated as two delimiters occurring back to back).
I saw a slight problem. If FIELDMINUS1 is zero, and the first field in the data to be matched is empty (meaning a line starts off with a delimiter rather than non-delimiter), then the match is incorrect. Maybe guru of gurus @guy038 could fix this problem,?