Wrong? No. It is just that your
.contains() regex pattern is too permissive. Likely an assumption that the summary was at the end of text. Plus, it can be confusing knowing when/in what contexts patterns work across line breaks (i.e. paragraph boundaries).
So, to test a better solutionI started a three paragraph test piece with the summary in the middle:
Having got a successful result, I added two edge cases where the summary is the beginning or the end of the $Text.
Again, a correct result so I can report the agent’s action is
$Subtitle=$1 as before but the revised queryis :
$Text.contains("Quick Summary: ([^\n]+)")
The regex parsed as pseudocode: The string "Quick Summary: "†, open a back-reference, match one or more non-line break characters‡, close back-reference
† This is case-sensitive so adjust for your summary label. Don’t forget the space(s) after the colon and before the actual summary text.
‡ i.e. match to the end of that paragraph (or end of the $Text if the last paragraph). This allows for your summary to be several short sentences if needs be. Note that detecting a sentence end is harder as you need to allow for full stop, question mark, exclamation mark, straight/curly single/double quotes (if those come after the punctuation mark - a BrE/AmE difference).
As you are using a subtitle, you probably don’t want to see the body $Text of the note. Shown by default, this can be suppressed. See $MapBodyTextSize.