|
| 1 | +import re |
| 2 | +def extract_course_times(): |
| 3 | + |
| 4 | + flask_course = ('Introduction 1 Lecture 01:47' |
| 5 | + 'The Basics 4 Lectures 32:03' |
| 6 | + 'Getting Technical! 4 Lectures 41:51' |
| 7 | + 'Challenge 2 Lectures 27:48' |
| 8 | + 'Afterword 1 Lecture 05:02') |
| 9 | + return re.findall(r'\d{2}:\d{2}', flask_course) |
| 10 | + |
| 11 | + |
| 12 | +def split_on_multiple_chars(): |
| 13 | + |
| 14 | + logline = ('2017-11-03T01:00:02;challenge time,regex!.' |
| 15 | + 'hope you join ... soon') |
| 16 | + return re.split(r'[;,\.]', logline, maxsplit=3) |
| 17 | + |
| 18 | + |
| 19 | +def get_all_hashtags_and_links(): |
| 20 | + tweet = ('New PyBites article: Module of the Week - Requests-cache ' |
| 21 | + 'for Repeated API Calls - http://pybit.es/requests-cache.html ' |
| 22 | + '#python #APIs') |
| 23 | + return re.findall(r'(?:http\S*)|(?:#\S*)', tweet) |
| 24 | + |
| 25 | + |
| 26 | +def match_first_paragraph(): |
| 27 | + html = ('<p>pybites != greedy</p>' |
| 28 | + '<p>not the same can be said REgarding ...</p>') |
| 29 | + return re.sub(r'<p>(.*)</p><p>.*</p>', lambda x: x.group(1), html) |
| 30 | + |
| 31 | + |
| 32 | +def find_double_words(): |
| 33 | + text = 'Spain is so nice in the the spring' |
| 34 | + return re.search(r'(\w{2,}) \1', text).group(0) |
| 35 | + |
| 36 | + |
| 37 | +def match_ip_v4_address(ip): |
| 38 | + return re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip) |
0 commit comments