Ok, so I read the post, which was super helpful. I got through tons of entries with only some slight edits to the expression here and there for changing context. So if I could take a bit more of your time, please let me see if I have parsed your expression correctly, and then let me follow up with something that I thought would work, but doesn't.
So this: regex([Name],/#(.+)Op.\s\d+\s(.+)#/,-1,0)[R1] [R2]
regex([Name], <-- This inputs the string to be parsed
/# <-- this says 'Regex expression starts here
(.+) <-- this says, Make R1 = everything from the beginning until...
Op. <-- ... you hit the string 'Op.'
\s <-- ... and a space?
\d+ <-- ... and some undetermined number of digits
\s <-- ... and another space?
(.+) <-- now make R2 = everything after that last space
#/ <-- end of expression
,-1,0) <-- Run in silent mode, which I don't quite understand, and be case insensitive, which I do understand
[R1] [R2] <-- create a new string with the values of R1 and R2
Ok, so if I have that correct, I am now trying to create an expression to do the opposite. I would like it to extract the composition number from the Name. I have the name:
Quintet for Horn, Violin, 2 Violas & Cello in E flat major KV 407-1.Allegro
And I want it to extract 407, so I have created the expression:
=regex([Name],/#.+\KV\s(\d+)\-(.+)#/,1,0)[R1]
And it almost works but returns:
407407
I cannot figure why the composition number has doubled up.