forked from bat67/The-Python-Standard-Library-by-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathre_split.py
More file actions
31 lines (24 loc) · 599 Bytes
/
Copy pathre_split.py
File metadata and controls
31 lines (24 loc) · 599 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Splitting input based on a pattern.
"""
#end_pymotw_header
import re
text = '''Paragraph one
on two lines.
Paragraph two.
Paragraph three.'''
print('With findall:')
for num, para in enumerate(re.findall(r'(.+?)(\n{2,}|$)',
text,
flags=re.DOTALL)):
print(num, repr(para))
print()
print()
print('With split:')
for num, para in enumerate(re.split(r'\n{2,}', text)):
print(num, repr(para))
print()