I want to populate markdown block quotes inside $Text to a specific attribute $Qotd
The block quotes are in a regular format (and the quotation marks are in the text):
> "This is a quote."
The following code works as expected:
if($Text.contains("^> (.+)\n")){$Qotd=$1;}
and $Qotd becomes "This is a quote." (i.e. it includes the original quotation marks.)
But if I try to remove the quotation marks in the output by escaping them in the pattern with:
if($Text.contains("^> \"(.+)\"\n")){$Qotd=$1;}
then the search still works, but the back reference doesnāt and I get $Qotd=$1.
The real code traps for failure, so I know the escape syntax is correct and the pattern is being found: itās the back reference which doesnāt work.
I know I could simply post-process $Qotd to strip the first and last character, but Iām interested to know:
Have I got the syntax wrong, or do " simply not work with back references?
I think the mistake is actually that Tinderbox, certainly at present (i.e. for later readers, v8.9.1), simply cannot backslash-escape single or double straight quotes. Bear in mind that Tinderbox core design long predates Markdown and action code is an evolved macro system and not a coding environment from the ground up. So, coding edge-case are likely to exist (and, I suspect) not easy to retro fix. Not least because the ability to escape straight quotes was first asked for long ago and hasnāt been taken up.
In this case, Iād use the approach you intimated. Try:
Note, neither .beginsWith() nor .endsWith() will match a " character - I tried! But if you wanted to test/trim separately for font-only or back-only quotes you could replace the second line above with these two tests:
Clarification. .beginsWith() nor .endsWith()do work in agents (and will match a "), but seemingly the operators donāt work at all as a test in if() conditional queries. Iāve reported this.
Well, youāll find that I lifted my solution from my notes on String.substr().
You might also want to see my recently revised notes on using regex back-references. In looking at it now, I need to clarify if backreferences are included in a quoted string or not. IOW, if $Text is āHello to you.ā:
all generate the string āHello and youā. So itās flexible, butānote to selfāI think it helps the learner to say so. Most ācodeā usage is not intuitive before the fact (except to those with some coding experience and even then they may guess wrongly first time).