Given a string, I would like to replace all abs by a, and all single as by 1, such that
X_ab_X-a%X
becomes
X_a_X-1%X
Replacing all as or all abs alone is pretty easy (here in JS)
mystring.replace(/a/gm, '1');
// mystring.replace(/ab/gm, 'a');
but I'm not seeing how to combine the two. All possible substrings can occur in mystring such that first replacing ab by TMP_UNIQUE_STRING won't work.
(Perhaps regexes aren't the right tool for the job.)