def search_regexp(self, pattern, audio_basename=None):
def indexes_in_transcript_to_start_end_second(index_tup,<EOL>audio_basename):<EOL><INDENT>"""<STR_LIT>"""<EOL>space_indexes = [i for i, x in enumerate(<EOL>transcription[audio_basename]) if x == "<STR_LIT:U+0020>"]<EOL>space_indexes.sort(reverse=True)<EOL>index_start, index_end = index_tup<EOL>index_end -= <NUM_LIT:1><EOL>while transcription[audio_basename][index_start] == "<STR_LIT:U+0020>":<EOL><INDENT>index_start += <NUM_LIT:1><EOL><DEDENT>while transcription[audio_basename][index_end] == "<STR_LIT:U+0020>":<EOL><INDENT>index_end -= <NUM_LIT:1><EOL><DEDENT>block_number_start = <NUM_LIT:0><EOL>block_number_end = len(space_indexes)<EOL>for block_cursor, space_index in enumerate(space_indexes):<EOL><INDENT>if index_start > space_index:<EOL><INDENT>block_number_start = (len(space_indexes) - block_cursor)<EOL>break<EOL><DEDENT><DEDENT>for block_cursor, space_index in enumerate(space_indexes):<EOL><INDENT>if index_end > space_index:<EOL><INDENT>block_number_end = (len(space_indexes) - block_cursor)<EOL>break<EOL><DEDENT><DEDENT>return (timestamps[audio_basename][block_number_start].start,<EOL>timestamps[audio_basename][block_number_end].end)<EOL><DEDENT>timestamps = self.get_timestamps()<EOL>if audio_basename is not None:<EOL><INDENT>timestamps = {audio_basename: timestamps[audio_basename]}<EOL><DEDENT>transcription = {<EOL>audio_basename: '<STR_LIT:U+0020>'.join(<EOL>[word_block.word for word_block in timestamps[audio_basename]]<EOL>) for audio_basename in timestamps}<EOL>match_map = map(<EOL>lambda audio_basename: tuple((<EOL>audio_basename,<EOL>re.finditer(pattern, transcription[audio_basename]))),<EOL>transcription.keys())<EOL>search_results = _PrettyDefaultDict(lambda: _PrettyDefaultDict(list))<EOL>for audio_basename, match_iter in match_map:<EOL><INDENT>for match in match_iter:<EOL><INDENT>search_results[match.group()][audio_basename].append(<EOL>tuple(indexes_in_transcript_to_start_end_second(<EOL>match.span(), audio_basename)))<EOL><DEDENT><DEDENT>return search_results<EOL>
First joins the words of the word_blocks of timestamps with space, per
audio_basename. Then matches `pattern` and calculates the index of the
word_block where the first and last word of the matched result appears
in. Then presents the output like `search_all` method.

Note that the leading and trailing spaces from the matched results
would be removed while determining which word_block they belong to.

Parameters
----------
pattern : str
    A regex pattern.
audio_basename : str, optional
    Search only within the given audio_basename.

    Default is `False`.

Returns
-------
search_results : {str: {str: [(float, float)]}}
    A dictionary whose keys are queries and whose values are
    dictionaries whose keys are all the audiofiles in which the query
    is present and whose values are a list whose elements are 2-tuples
    whose first element is the starting second of the query and whose
    values are the ending second. e.g.
    {"apple": {"fruits.wav" : [(1.1, 1.12)]}}