from typing import Optional
from typing import List
import re
import itertools


def get_expanded_article_pages(page_ref: Optional[str]) -> List[int]:
    """['p. D-D', 'p. D', 'p. D, D ', 'p. D, D-D ', 'p.D-D', 'p.D',
    'p. D-D, D ', 'page D', 'p., D-D', 'p. D-D, D-D ']"""

    if page_ref is None:
        return []
    pr = re.sub(r'^(p\.\,?|pages?)', '', str(page_ref or '')).replace(' ', '').split(',')
    ix = itertools.chain(
        *(
            [list(range(int(x), int(y) + 1)) for x, y in [w.split('-') for w in pr if '-' in w]]
            + [[int(x)] for x in pr if '-' not in x]
        )
    )
    return sorted(list(ix))