pyxx.strings.find_skip_brackets¶
- pyxx.strings.find_skip_brackets(value: str, target_chars: str | tuple, begin: int, direction: str = 'forward', opening_bracket: str = '(', closing_bracket: str = ')') int¶
Finds the index of a target character, skipping over matched brackets
This function is useful for finding the index of a particular character in a string, ignoring content inside of matched brackets. It begins at a given index in a string and searches until any of a given set of target character(s) are found. If an opening or closing bracket is reached, the function skips to the corresponding matched bracket before resuming the search (i.e., content inside of matched brackets is not searched).
- Parameters:
value (str) – String to search
target_chars (str or tuple) – A string or tuple with one or more characters to search for
begin (int) – Index in
valueat which to begin searchingdirection (str, optional) – Whether to search
valuein order of increasing or decreasing index. Can be either'forward'or'reverse'(default is'forward')opening_bracket (str, optional) – Character representing opening bracket (default is
'(')closing_bracket (str, optional) – Character representing closing bracket (default is
')')
- Returns:
The index of the first occurrence of any characters in
target_charsfound invalue, beginning the search at indexbeginand searching in the direction specified bydirectionand ignoring content inside of matched brackets. If none oftarget_charsare found,-1is returned- Return type:
int
Notes
When searching, the function will not “enter” matched brackets; however, if the index specified by
beginis inside a set of brackets, the function will search inside of these brackets and can “leave” these brackets and search in parts of the string outside these brackets