MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / last_word

Function last_word

web/pgadmin/utils/sqlautocomplete/parseutils/utils.py:18–63  ·  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

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

Callers 4

__init__Method · 0.85
find_matchesMethod · 0.85
get_column_matchesMethod · 0.85

Calls 1

searchMethod · 0.80

Tested by

no test coverage detected