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