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 value at which to begin searching

  • direction (str, optional) – Whether to search value in 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_chars found in value, beginning the search at index begin and searching in the direction specified by direction and ignoring content inside of matched brackets. If none of target_chars are found, -1 is returned

Return type:

int

Notes

When searching, the function will not “enter” matched brackets; however, if the index specified by begin is 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