From 8f1b2a32fa09a61e3f37f97c307b39f193c60043 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 9 May 2020 13:35:45 -0700 Subject: [PATCH] ;csv: start regexp examples section, show field equality testing --- hledger-lib/hledger_csv.m4.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hledger-lib/hledger_csv.m4.md b/hledger-lib/hledger_csv.m4.md index f47ace06e..547e61a9b 100644 --- a/hledger-lib/hledger_csv.m4.md +++ b/hledger-lib/hledger_csv.m4.md @@ -892,3 +892,18 @@ This is all part of the CSV reader, one of several readers hledger can use to parse input files. When all files have been read successfully, the transactions are passed as input to whichever hledger command the user specified. + +## Regular expression tricks + +### Testing that two fields have the same value + +```csv +2020-01-01,different,3,4,5,6,7,8,9 +2020-01-01,same ,3,4,5,6,7,7,9 +``` +```rules +fields date,description,_,amount,_,_ +# skip first 6 fields, then match if the next two fields are the same +if ^([^,]*,){6}([^,]*),\7 + comment fields 7 and 8 have the same value +```