예제 #1
0
def headlined_sections(string, headline_pattern):
    """ return sections with headlines matching a pattern
    """
    lines = string.splitlines()
    join_lines = '\n'.join
    pattern_matcher = apf.matcher(headline_pattern)
    lines = mit.lstrip(lines, pred=lambda line: not pattern_matcher(line))
    sections = list(map(join_lines, mit.split_before(lines, pattern_matcher)))
    return sections
예제 #2
0
def headlined_sections(string, headline_pattern):
    """ Returns sections with headlines matching a pattern.

        :param string: string to return sections
        :type string: str
        :param headline_pattern: pattern to demarcate strings into sections
        :type headline_pattern: str
        :rtype: str
    """

    lines = string.splitlines()
    join_lines = '\n'.join
    pattern_matcher = apf.matcher(headline_pattern)
    lines = mit.lstrip(lines, pred=lambda line: not pattern_matcher(line))
    sections = list(map(join_lines, mit.split_before(lines, pattern_matcher)))

    return sections