MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / last_word

Function last_word

mssqlcli/packages/parseutils/utils.py:19–62  ·  view source on GitHub ↗

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')

Source from the content-addressed store, hash-verified

17
18
19def 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
65def find_prev_keyword(sql, n_skip=0):

Callers 4

find_matchesMethod · 0.90
get_column_matchesMethod · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected