Bash has built-in facilities to trim characters at the beginning and end of the value of a variable:

$ myvar="AAAthis is a testAAA"
$ echo ${myvar##*(A)}
this is a testAAA
$ echo ${myvar%%*(A)}
AAAthis is a test

I work as a freelancer, so if you don’t want to do that kind of things yourself or don’t have the time, just drop me a line to hire me.