Last active
July 18, 2021 16:16
-
-
Save boydx/2471d30a91119cee534042870035296a to your computer and use it in GitHub Desktop.
Add leading 0 stripped from FIPS code in CSV files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a problem when number string fields are encoded as numbers. | |
Regex expression in VS Code where the FIPS code column is surrounding by two string fields. | |
step 1: | |
find pattern breaks search into two subexpressions | |
(",)([0-9]{4},") | |
step 2: | |
replace pattern inserts 0 in front of the second subexpression | |
$10$2 | |
To wrap FIPS codes in quotes, find the comma before and after the 5-digit number. Insert quote. | |
Search pattern to find the comma after a 5-digit string (in a CSV whose first column contains a FIPS code) | |
(^"[0-9]{5})(,) | |
Replace pattern using subexpressions | |
$1"$2 | |
Select everythign between two commas | |
(?<=,)[^,]+(?=,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment