search_ module¶
Utilities for searching.
FIRST_TOKEN_REGEX Pattern¶
First token regex for parse_path_str.
Matches the same as PATH_TOKEN_REGEX but at the start.
PATH_TOKEN_REGEX Pattern¶
Path token regex for parse_path_str.
Matches .key, ['key'], ["key"], [0], .0, etc.
search_config ReadonlyConfig¶
Config of functions that can be used in searching and replacement.
ReadonlyConfig(
find_exact=<function find_exact at 0x122392020>,
find_start=<function find_start at 0x1223920c0>,
find_end=<function find_end at 0x122392160>,
find_substring=<function find_substring at 0x122392200>,
find_regex=<function find_regex at 0x1223922a0>,
find_fuzzy=<function find_fuzzy at 0x122392340>,
find_rapidfuzz=<function find_rapidfuzz at 0x122392480>,
find=<function find at 0x122392520>,
replace_exact=<function replace_exact at 0x1223925c0>,
replace_start=<function replace_start at 0x122392660>,
replace_end=<function replace_end at 0x122392700>,
replace_substring=<function replace_substring at 0x1223927a0>,
replace_regex=<function replace_regex at 0x122392840>,
replace_fuzzy=<function replace_fuzzy at 0x1223928e0>,
replace=<function replace at 0x122392980>
)
combine_path_str function¶
Combine two path strings into one.
combine_pathlike_keys function¶
Combine two path-like keys.
contains_in_obj function¶
contains_in_obj(
obj,
match_func,
traversal=None,
excl_types=None,
incl_types=None,
max_len=None,
max_depth=None,
**kwargs
)
Return whether there is any match in an object in an iterative manner.
Argument traversal can be "DFS" for depth-first search or "BFS" for breadth-first search.
See find_in_obj for arguments.
find function¶
Find a target within a string using the specified mode and return type.
The following return types are supported:
- "bool": True for match, False for no match
- "start": List of start indices of matches
- "range": List of (start, end) tuples of matches
- "match": List of matched strings
find_and_replace_in_obj function¶
find_and_replace_in_obj(
obj,
match_func,
replace_func,
excl_types=None,
incl_types=None,
max_len=None,
max_depth=None,
make_copy=True,
check_any_first=True,
**kwargs
)
Find and replace matches in an object in a recursive manner.
See find_in_obj for arguments.
Note
If the object is deep (such as a dict or a list), creates a copy of it if any match found inside, thus losing the reference to the original. Make sure to do a deep or hybrid copy of the object before proceeding for consistent behavior, or disable make_copy to override the original in place.
find_end function¶
Find at the end of a string.
find_exact function¶
Find a string.
find_fuzzy function¶
find_fuzzy(
target,
string,
ignore_case=False,
threshold=70,
max_insertions=None,
max_substitutions=None,
max_deletions=None,
max_l_dist=None,
return_type='bool'
)
Find a substring in a string using fuzzysearch.
find_in_obj function¶
find_in_obj(
obj,
match_func,
traversal=None,
excl_types=None,
incl_types=None,
stringify_keys=False,
max_len=None,
max_depth=None,
**kwargs
)
Find matches in an object in an iterative manner.
Traverses dicts, tuples, lists and (frozen-)sets. Does not look for matches in keys.
Argument traversal can be "DFS" for depth-first search or "BFS" for breadth-first search.
If excl_types is not None, uses is_instance_of to check whether the object is one of the types that are blacklisted. If so, the object is simply returned. Same for incl_types for whitelisting, but it has a priority over excl_types.
If max_len is not None, processes any object only if it's shorter than the specified length.
If max_depth is not None, processes any object only up to a certain recursion level. Level of 0 means dicts and other iterables are not processed, only matches are expected.
Returns a map of keys (multiple levels get represented by a tuple) to their respective values.
For defaults, see search.
find_rapidfuzz function¶
find_rapidfuzz(
target,
string,
ignore_case=False,
processor=None,
threshold=70,
return_type='bool'
)
Find a substring in a string using RapidFuzz.
find_regex function¶
Find a RegEx pattern in a string.
find_start function¶
Find at the start of a string.
find_substring function¶
Find a substring in a string.
flatten_obj function¶
flatten_obj(
obj,
traversal=None,
annotate_all=False,
excl_types=None,
incl_types=None,
stringify_keys=False,
max_len=None,
max_depth=None
)
Flatten object.
Argument traversal can be "DFS" for depth-first search or "BFS" for breadth-first search.
See find_in_obj for arguments.
get_pathlike_key function¶
Get the value under a path-like key in an object.
Paths can be tuples out of individual tokens, or a string with tokens. Each token can be either a key in a mapping, a position in a sequence, or an attribute.
Usage
>>> obj = dict(a=[dict(b="cde")])
>>> vbt.utils.search_.get_pathlike_key(obj, "a")
[{'b': 'cde'}]
>>> vbt.utils.search_.get_pathlike_key(obj, ("a", 0))
>>> vbt.utils.search_.get_pathlike_key(obj, "a.0")
>>> vbt.utils.search_.get_pathlike_key(obj, "a[0]")
{'b': 'cde'}
>>> vbt.utils.search_.get_pathlike_key(obj, ("a", 0, "b"))
>>> vbt.utils.search_.get_pathlike_key(obj, "a[0].b")
>>> vbt.utils.search_.get_pathlike_key(obj, "a[0]['b']")
'cde'
>>> vbt.utils.search_.get_pathlike_key(obj, ("a", 0, "b", 1))
>>> vbt.utils.search_.get_pathlike_key(obj, "a[0].b[1]")
'd'
minimize_pathlike_key function¶
Minimize a path-like key.
parse_path_str function¶
Parse the path string into a list of tokens.
remove_pathlike_key function¶
Remove the value under a path-like key in an object.
replace function¶
Replace a target string within a source string using the specified mode.
replace_end function¶
Replace at the end of a string.
replace_exact function¶
Replace a string.
replace_fuzzy function¶
replace_fuzzy(
target,
replacement,
string,
ignore_case=False,
threshold=70,
max_insertions=None,
max_substitutions=None,
max_deletions=None,
max_l_dist=None
)
Replace a substring in a string using fuzzysearch.
replace_in_obj function¶
Replace matches in an object in a recursive manner using a path dictionary.
Keys in the path dictionary can be path-like keys.
replace_regex function¶
Replace a target in a string using RegEx.
replace_start function¶
Replace at the start of a string.
replace_substring function¶
Replace a substring in a string.
resolve_pathlike_key function¶
Convert a path-like key into a path key.
set_pathlike_key function¶
Set the value under a path-like key in an object.
stringify_pathlike_key function¶
Convert a path-like key into a string.
unflatten_obj function¶
Unflatten object in a recursive manner using a path dictionary.
Keys in the path dictionary can be path-like keys.
Not class¶
Class representing a negation when searching.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- DefineMixin.asdict
- DefineMixin.assert_field_not_missing
- DefineMixin.fields
- DefineMixin.fields_dict
- DefineMixin.get_field
- DefineMixin.hash
- DefineMixin.hash_key
- DefineMixin.is_field_missing
- DefineMixin.is_field_optional
- DefineMixin.is_field_required
- DefineMixin.merge_over
- DefineMixin.merge_with
- DefineMixin.replace
- DefineMixin.resolve
- DefineMixin.resolve_field
- Hashable.get_hash
value field¶
Value.