It may be that the only regular expression you need is \s+@
(Splitting text into substrings is the more natural home of regular expressions – the search and replace pattern strains them a bit, adding redundant complexity)
Check your regex carefully, and/or post the actual "Search and Replace" Action here. What you've written should work, but I suspect you've accidentally put a . before the *
Sometimes the KM Engine can lag behind changes in the Editor, so try:
Quitting then opening the Editor, to force a plist re-write, then...
Quitting and relaunching the Engine (in the Editor, File->Quit Engine then File->Launch Engine) to force the Engine to reload the fresh plist
Also, I'm guessing that your last two AppleScript Actions are either erroring or doing something unexpected. They're unnecessary anyway -- much quicker and easier to use the native "New Folder" and "Move a File or Folder" Actions -- but if you must use AS then read the Wiki's "Execute an AppleScript"page to see how you should be passing in KM variables.
Have a go at replacing those AS Actions with the KM ones, and if you get stuck then just ask here -- you'll get better results than going to an AI...
My concern would be time -- instead of a couple milliseconds to process the text, regardless of length, the "For Each"/pseudo array method will take ~3ms per line of text. Not too bad for a list of book chapters (unless it's a very long book!), but something to be aware of.
The regex should work, and is actually over-complicated given that the input data is strictly formatted. This will work just as well:
(?m)^#(.*?) *@(\d*)
...unless you have chapter names like "The Boy Who Failed @12"...
First - it may be other of many cases of format of TOC (ellen in other thread on this forum presented another format of TOC) so regex is better way to service different variants.
Second - we always test regex on that what was pasted here, not what is inside original file read by macro. To be absolutely sure the test should be done on exact copy of input file.
Yes, it's a better pattern because it catches tabs as well.
But, as I showed above, the pattern isn't the problem if the inputs we've been given are correct. The "obvious" way to get incorrect results is
(?m)^#([^@\n])+?.*@(\d*)
...and it may be that OP tried something like that first, changed the regex, but the plist didn't update and/or the Engine didn't reload the new version.