Extracting 'side', v2.39c

I need a Export script expression to extract the side (e.g. CD) number from directory names such as

40 Grandes Exitos [CD1] [8427328146067]\01 Patotero sentimental.mp3 --> 1
40 Grandes Exitos [CD2] [8427328146067]\01 Porteño y bailarín.mp3 --> 2
07798108080576d1_Piazzolla_Grandes_del_tango\01-AudioTrack_01_400fa817.flac --> 1
07798108080576d2_Piazzolla_Grandes_del_tango\01-AudioTrack_01_7910b619.flac --> 2

The only thing fixed about the directory name format is that for each CD in an album it differs from the other CDs in only the side number.

I can see that without a script function to find the difference between two strings, this will be tricky!


Any suggestions, experts?