import re
import json


def read(filename, regex):
    """Read file, filter by regex, add space between characters
    """
    with open(filename, encoding='utf-8') as f:
        documents = f.readlines()

    r = re.compile(regex)
    # Each line is a full article
    for i, line in enumerate(documents):
        text = json.loads(line)['text']
        text = text.replace('\\n', '\n').strip()
        res = ''
        for c in text:
            c = r.match(c)
            if c:
                res += ' ' + c.string
        documents[i] = res

    return documents