获取正则匹配到的文本 :param text: 需要匹配的文本 :param pattern: 正则 :return: 符合正则的文本
(text, pattern: str)
| 174 | |
| 175 | |
| 176 | def parse_level(text, pattern: str): |
| 177 | """ |
| 178 | 获取正则匹配到的文本 |
| 179 | :param text: 需要匹配的文本 |
| 180 | :param pattern: 正则 |
| 181 | :return: 符合正则的文本 |
| 182 | """ |
| 183 | masked_text = mask_code_blocks(text) |
| 184 | level_content_list = list(map(to_tree_obj, [r[0:255] for r in re_findall(pattern, masked_text) if r is not None])) |
| 185 | # 过滤掉空标题或只包含#和空白字符的标题 |
| 186 | filtered_list = [item for item in level_content_list |
| 187 | if item['content'].strip(' ') and item['content'].replace('#', '').strip(' ')] |
| 188 | return list(map(filter_special_symbol, filtered_list)) |
| 189 | |
| 190 | |
| 191 | def re_findall(pattern, text): |
no test coverage detected