Unable to regex on aggregation filter input box

I have the following metrics from a aws service: api-name-404, api-name-406, api-name-501,api-name-500.
I wrote the aggregation filter query using regex. But since I want to show 5xx and 4xx errors in same graph, I have used a sum bucket aggregation.
In order to filter out all 5xx errors under same bucket and used in a filter, I tried using this in the box like this: metric.name:api-name-5 but this doesn't work as it expect a full text match, and doesn't filter all 5xx errors.
I tried several options to use a regex but looks impossible in the filter box for filters aggregation.

I have wrote a query filter to retrieve all the 5xx errors as follows and this works.

But as I showed in the first figure, I can't use a regex to filter all class of 5xx errors under same filter. I can only show either 500 or 501 or so.

Any idea how to achieve the same?

This is because what you're using in the top filter that you edited is Query DSL while the Filters in aggregation uses KQL. 5* should work if the field is set to keyword afaik. Since you only have those 4 values I highly recommend just using AND/ OR in order to make the queries faster.