Showing posts with label regular expression. Show all posts
Showing posts with label regular expression. Show all posts

2016-01-07

Validating CSV file with regular expressions / Проверка CSV файла регулярным выражением

The CSV file does not contain double quote.
14 commas (field delimiter) are expected in each row.
A row delimiter is CRLF (\r\n).

Searching for a row with 15 commas in Notepad++ :
^([^,\r]*,){15}
[^,\r]* matches any char except comma and CR

2014-08-12

Regular expressions for CSV files

SQL Server Import had troubles to import csv file, when some fields contained CRLF(\r\n).
Row delimiter needs to be changed.
Notepad++ was used.

It matches 15 columns (14 comma delimiters). CRLF is end of line. Some text columns contain CRLF(\r\n).
((?:(?:"(?:(?:""|[^"])+)"|(?:[^,]*)),){14}.*?)\r\n
to add a pipe as row delimiter replace with \1|\r\n

it matches $$ delimiter 7 fields (6 delimiters) and end of line \r MAKE sure . dot matches end of LINE!
(?:.*?\$\$){6}.*?\r
((?:.*?\$\$){13}.*?)\r\n   to add a pipe as row delimiter replace with \1|\r\n 

to search for $$ with grep (Linux or Cygwin), use single quotes and escape last dollar
grep -e '$\$' filename.csv