<li><a href="ExampleStoryC1.html" title="Example Story chapter 1: Quite An Introduction">Quite An Introduction</a></li>
<li><a href="ExampleStoryC2.html" title="Example Story chapter 2: Moving the Plot Forward">Moving the Plot Forward</a></li>
<li><a href="ExampleStoryC3.html" title="Example Story chapter 3: Things Get Messy">Things Get Messy</a></li>
<li><a href="ExampleStoryC4.html" title="Example Story chapter 4: Life Is Better">Life Is Better</a></li>
<li><a href="ExampleStoryC5.html" title="Example Story chapter 5: Adulting Sucks!">Adulting Sucks!</a></li>
<li><a href="ExampleStoryC6.html" title="Example Story chapter 6: Aging Is Worse">Aging Is Worse</a></li>
<li><a href="ExampleStoryC7.html" title="Example Story chapter 7: Let’s Not Talk About Late Life">Let’s Not Talk About Late Life</a></li>
<li><a href="ExampleStoryC8.html" title="Example Story chapter 8: Epilog">Epilog</a></li>
set StoryTitle to "Example Story"
set ConcatStoryTitle to "ExampleStory"
-- In reality, ^those titles^ are set and used much earlier in the much longer overall script
tell application "BBEdit"
tell text document 1
replace "(\\d\\d?)(.+?)</a>" using "<li><a href=\"" & ConcatStoryTitle & "C" & (grep substitution of ("\\1" as text)) & ".html\" " & "title=\"" & StoryTitle & " chapter " & (grep substitution of ("\\1" as text)) & ": " & (grep substitution of ("\\2" as text)) & "\">" & (grep substitution of ("\\2" as text)) & "</a>" options {search mode:grep, wrap around:true}
end tell
end tell
When i run the script, the Events look like this:
tell application "BBEdit"
grep substitution of "\\1"
Result:
error "BBEdit got an error: The replacement string couldn’t be computed, because the previous Grep search did not succeed (application error code: 12003)" number 12003
I haven’t been able to figure out what i’m doing wrong. Looking forward to learning something else new about scripting BBEdit.
find "(\\d\\d?)(.+?)</a>" options {search mode:grep, wrap around:true} with selecting match
set chapnumtest to grep substitution of ("\\1" as text)
set chaptitletest to grep substitution of ("\\2" as text)
log chapnumtest
log chaptitletest
So this tells me that my Grep string is valid (which i know from it working with the manual not scripted Replace All), making it all the more puzzling to me why it fails in a scripted replace (all).