Hey there, great sample of the use of split and back-references. Once crucial point. Curly brackets are a RegEx operator. For @eastgate example to work you need to escape the brackets with a backslash \
.
I’ve created a sample file with three approaches to the problem. Also, it includes a logging example. I will go over things today in today’s meetup, as I think it holds a ton of valuable lessons.
This lesson is in response to a post by @jprint714
How to name $Title and move $Text for notes containing bracketed titles?. This is a wonderful tutorial that gets at the root of action code, logging, text transformation, note name path management and more
Description
Parse the text in an attribute and place the different parts in different attributes.
Learning Outcome
-
Know how to use .split operator
-
Appreciate the retention of your source data until you’re ready to destroy it
-
Missed typed operators can lead to data being inexplicably destroyed (see LO2)
-
Logging is your friend, helps you see what’s going on.
-
Commenting code is your friends, it helps your future-self
-
There is more than one way to do something
-
Understand RegEx operational characters and how to escape them
-
Tinderbox’s syntax for finding keys in a list or dictionary, e.g. [0], [1].
-
User of designators, e.g. a note name, path, to enhance action code.
-
The use of variables
-
Appreciate the value of cleaning up after yourself
-
Bonus: writing in markdown gives a ton of flexibility
-
Bonus: some visual affordance really help, e.g., views, separators, and badges
-
Bonus: replacing tricky characters, e.g., “;”, in operations with a different delimiter to complete a process and then later refers back to the original.
-
Bonus: Triggering functions.
Objective:
Parse this text “{1492: Columbus Sails} Columbus departs from Palos, Spain” that is in the $Name of a note.
-
Place the text between the{} in the $Name
-
Place the remaining text in $Text
-
Do it in a way that leaves no lingering data
The Solution
See the stamps. I’ve produced several for the exercise:
-
Reset
-
Parse Name Original 0, the stamp that does not work
-
Parse Name Original 1, simple stamp
-
Parse Name Original 2 Modified, handles “;” in text.
-
Parse =Name Refined Eg 1 Use Attribute Placeholder , uses attributes as placeholder
-
Parse Name Refined Eg 2 Use Variable uses variables instead of attributes.
-
Tigger Parse Note, triggers a function to parse the note
See the functions, I’ve created two functions.
-
fParseNote, parses the note on a boolean trigger
-
fReset, resets the note on a boolean trigger
TBX L - Meetup 23OCT22 Using Split to Parse Data.tbx (303.1 KB)