How does Shell perform regular replacement?

for example, I have a string variable that reads:

AAA=<?=\${AAA}=?>
BBB=<?=\${BBB}=?>
<%=[ "\${Alias}" == "" ]=%>
CCC=\${CCC}

I want to implement regular substitution, generating the string as

AAA=<?=${AAA}=?>
BBB=<?=${BBB}=?>
<%= [ "${Alias}" == "" ] =%>
CCC=\${CCC}

or

AAA=${AAA}
BBB=${BBB}
[ "${Alias}" == "" ]
CCC=\${CCC}

how to achieve it? I tried sed, etc., but the ability of Shell is limited, so it is difficult to achieve the effect.

Note: I want to achieve the effect of template engine replacement.


because the question has been corrected, the answer is also updated:
you can solve your problem with grep and sed

echo 'AAA=<?=\${AAA}=?>' | grep -E '<[?%]=.*=[?%]>' | sed 's/\\\$/$/g' | sed 's/<[?%]=//g' | sed 's/=[?%]>//g'

above, return AAA=$ {AAA} . Similarly, the above statement applies to <% = ["\ ${Alias}" = "] =% > .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32764-2be0c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32764-2be0c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?