r""" Find the last word in a sentence. >>> last_word('abc') 'abc' >>> last_word(' abc') 'abc' >>> last_word('') '' >>> last_word(' ') '' >>> last_word('abc ') '' >>> last_word('abc def') 'def' >>> last_word('abc def ') '' >>> last_word
(text, include='alphanum_underscore')
| 17 | |
| 18 | |
| 19 | def last_word(text, include='alphanum_underscore'): |
| 20 | r""" |
| 21 | Find the last word in a sentence. |
| 22 | |
| 23 | >>> last_word('abc') |
| 24 | 'abc' |
| 25 | >>> last_word(' abc') |
| 26 | 'abc' |
| 27 | >>> last_word('') |
| 28 | '' |
| 29 | >>> last_word(' ') |
| 30 | '' |
| 31 | >>> last_word('abc ') |
| 32 | '' |
| 33 | >>> last_word('abc def') |
| 34 | 'def' |
| 35 | >>> last_word('abc def ') |
| 36 | '' |
| 37 | >>> last_word('abc def;') |
| 38 | '' |
| 39 | >>> last_word('bac $def') |
| 40 | 'def' |
| 41 | >>> last_word('bac $def', include='most_punctuations') |
| 42 | '$def' |
| 43 | >>> last_word('bac \def', include='most_punctuations') |
| 44 | '\\\\def' |
| 45 | >>> last_word('bac \def;', include='most_punctuations') |
| 46 | '\\\\def;' |
| 47 | >>> last_word('bac::def', include='most_punctuations') |
| 48 | 'def' |
| 49 | >>> last_word('"foo*bar', include='most_punctuations') |
| 50 | '"foo*bar' |
| 51 | """ |
| 52 | |
| 53 | if not text: # Empty string |
| 54 | return '' |
| 55 | |
| 56 | if text[-1].isspace(): |
| 57 | return '' |
| 58 | regex = cleanup_regex[include] |
| 59 | matches = regex.search(text) |
| 60 | if matches: |
| 61 | return matches.group(0) |
| 62 | return '' |
| 63 | |
| 64 | |
| 65 | def find_prev_keyword(sql, n_skip=0): |
no outgoing calls
no test coverage detected