Thank you for your feedback.
Finally I have solved nesting the regexp_matches functions inside sub-select and selecting the first row with [1]
It works for me.
select message as before,
replace(message,
(select regexp_matches(message,'\\$\\$.*?\\{tabular\\}.*?\\$\\$','n'))[1],
replace((select regexp_matches(message,'\\$\\$.*?\\{tabular\\}.*?\\$\\$','n'))[1],'{tabular}','{array}')) as later
from mdl_forum_posts
where message ~ '\\$\\$.*?\\{tabular\\}.*?\\$\\$';