import re
from typing import Counter


def _get_table_width(table_spec):
    """Calculate the width of a table based on its spec.

    :param table_spec:

    :type table_spec: str

    :return:
    :rtype: int
    """

    column_letters = ['l', 'c', 'r', 'p', 'm', 'b']

    # Remove things like {\bfseries}
    cleaner_spec = re.sub(r'{[^}]*}', '', table_spec)
    spec_counter = Counter(cleaner_spec)

    return sum(spec_counter[l] for l in column_letters)